0
votes

was working in Xcode 4.6 and have a UItableview set up where the cells are populated from an array. When working in 4.6, the view behaved perfectly and was just how I liked it. After the update to 5.1.1, scrolling seems to have been enabled on the table view, the table view is loaded from the bottom of the view and the 3 populated cells at the top are not visible. Sometimes the view will rubber band and not allow me to scroll all the way back up to the top, and sometimes it won't rubber band and will let me. I am fairly new to this, but have tried messing around with auto layout, but to no avail.

Here's my code for the .h

@interface TableViewController : UITableViewController
@property (nonatomic, strong) NSArray *Manufacturers;
@end

Here's my code for the .m:

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];


_Manufacturers = @[@"1",
               @"2",
               @"3"];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return _Manufacturers.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath            *)indexPath
{
static NSString *CellIdentifier = @"TableCell";
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier   forIndexPath:indexPath];

// Configure the cell...

int row = [indexPath row];

cell.TitleLabel.text = _Manufacturers[row];


return cell;
}
2
Is TableCell is custom cell?Himanshu Joshi
Thanks of the reply. What exactly do you mean by custom cell?user3580512
Custom Cell means you are overriding the default UITableViewCellHimanshu Joshi

2 Answers

0
votes

In cellForRowAtIndexPath:

If you are using default UITableViewCell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath            *)indexPath
{
    static NSString *CellIdentifier = @"TableCell
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyIdentifier"];

    }
    int row = [indexPath row];
    cell.textLabel.text = _Manufacturers[row];

    return cell;
}

If you are using custom TableViewCell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableCell";

    SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil) 
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    } 

    cell.nameLabel.text = [tableData objectAtIndex:indexPath.row];

    return cell;
}
0
votes

TableCell is Custom than write below code..

 TableCell *cell = (TableCell*)[tableView  dequeueReusableCellWithIdentifier:cellIdentifier];
 NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TableCell" owner:self options:nil];
 cell = [nib objectAtIndex:0];

Otherwise

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
 UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

Look at this tutorial for custom cell http://www.appcoda.com/customize-table-view-cells-for-uitableview/