我工作的一個應用程序,我有填充了該方法的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