简体   繁体   中英

why [self.tableView reloadData] does not Work?

This is the code for cellForRowAtIndexPath: method.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];

if (cell == nil) { cell = [[[UITableViewCell alloc]
    initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}

NSUInteger row = [indexPath row]; 
cell.textLabel.text = [array objectAtIndex:row]; 
return cell;    
}

When i use [self.tableView reloadData]; nothing happening?

You need to implement at least the tableView:numberOfRowsInSection: method as part of the UITableViewDataSource protocol, and tableView:cellForRowAtIndexPath: (which you already did). You should also implement numberOfSectionsInTableView: .

Then you need to make sure that your class is actually used as a data source:

self.tableView.dataSource = self;

That needs to be either done via Interface Builder or in awakeFromNib or some other method like viewDidLoad: .

Do you check your dataSource and delegate of UITableView ? I think the dataSource is nil or something else.

Try putting a break point in cell for row and see if it is called when u call reloadData. Also pls check if the changes are already made to array from which the cells are populated and make sure the table view is connected to its datasource and delegate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM