相关疑难解决方法(0)

cellForRowAtIndexPath返回null值

我正在开发一个应用程序,我有一个UITableView,它使用方法tableView:cellForRowAtIndexPath:填充NSMutableArray,它工作正常,但问题是我想更改tableViewCell的图像,当我尝试访问单元格时它总是返回null.我在这里给出代码,请告诉我是否遗漏了一些东西......

在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
Run Code Online (Sandbox Code Playgroud)

在视图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];
    }

    - …
Run Code Online (Sandbox Code Playgroud)

iphone uitableview ios xcode4.2

1
推荐指数
1
解决办法
4170
查看次数

标签 统计

ios ×1

iphone ×1

uitableview ×1

xcode4.2 ×1