Я работаю над приложением, у меня есть UITableView, который заполняется NSMutableArray с методом tableView: cellForRowAtIndexPath :, он работает нормально, но проблема в том, что я хочу изменить изображение для tableViewCell, когда я пытаюсь доступ к ячейке всегда возвращает ноль. Я даю код здесь, пожалуйста, скажите мне, я что-то упустил ...
в файле 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
в файле view 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;
}