我工作的一个应用程序,我有填充了该方法的tableView一个NSMutableArray一个UITableView::,的cellForRowAtIndexPath它工作正常,但问题是,我想改变形象为tableViewCell,当我尝试访问单元格时,它总是返回null。我在这里给的代码,请告诉我,我是否失去了一些东西......的cellForRowAtIndexPath返回空值
在viewController.h文件
@interface DevicesViewController : UIViewController{
IBOutlet UITableView *deviceTableVIew;
NSMutableArray *devicesArray;
NSMutableArray *deviceDetailArray;
}
@property (nonatomic,retain) IBOutlet UITableView *deviceTableVIew;
@property (nonatomic,retain) NSMutableArray *devicesArray;
@property (nonatomic,retain) NSMutableArray *deviceDetailArray;
-(IBAction)setDevicesOn:(id)sender;
-(IBAction)setDevicesOff:(id)sender;
@end
视图Controller.m或者文件
-(IBAction)setDevicesOn:(id)sender{
UITableViewCell *cell = [deviceTableVIew cellForRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:1]];
cell.imageView.image = [UIImage imageNamed:@"device-on-image.png"];
[deviceTableVIew reloadData];
...
}
-(IBAction)setDevicesOff:(id)sender{
UITableViewCell *cell = [deviceTableVIew cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
cell.imageView.image = [UIImage imageNamed:@"device-off-image.png"];
[deviceTableVIew reloadData];
...
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [devicesArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [devicesArray objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [deviceDetailArray objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:@"device-off-image.png"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
向你展示的cellForRowAtIndexPath – janusbalatbat 2012-03-13 12:31:52