我写了一个继承自UITableViewController的子类,其中一个函数会导致程序一启动就挂掉。我把那个函数给注释掉程序就不会出错了,那个函数是:- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[masterColorList objectAtIndex:section] count];
}
{
return [[masterColorList objectAtIndex:section] count];
}
解决方案 »
- address doesn't contain a section that points to a section in a object file
- IPad上录音后播放,声音比较小,可以怎么调节吗?
- Security.framework 对java服务端证书验签问题
- 地图大头钉问题
- iPhone 调用wifi ,找不到WiFiManager
- 为什么字符串压缩之后不是zip包
- 【图片旋转】很怪异的问题
- app管理软件怎么实现下载和安装第三方app分离?
- UITableViewCell选中后其下的UILabel标签背景色消失
- 请教投射功能
- 一个MKMapView的问题,请高手解答。
- 新手,问个入门问题
section 应该超过了 masterColorList 的 count,
做个测试。
还有个函数,numberOfSections 你返回的是多少。
@interface RootViewController : UITableViewController
{
NSArray *masterColorList;
}@property(retain)NSArray *masterColorList;
@end代码文件:#import "RootViewController.h"
#import "CoreGraphics/CGGeometry.h"
@implementation RootViewController
@synthesize masterColorList;- (id)initWithCoder:(NSCoder *)decoder
{
if (self = [super initWithCoder:decoder])
{
NSArray *colorList = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"brownColor",@"titleValue",[UIColor brownColor],@"colorValue",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"orangeColor",@"titleValue",[UIColor orangeColor],@"colorValue",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"purpleColor",@"titleValue",[UIColor purpleColor],@"colorValue",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"redColor", @"titleValue",[UIColor redColor],@"colorValue",nil],
nil];
NSArray *otherColorList = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"RGB:0.25/0/0", @"@titleValue",[UIColor colorWithRed:0.25 green:0 blue:0 alpha:1],@"colorValue",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"RGB:0.5/0/0", @"@titleValue",[UIColor colorWithRed:0.5 green:0 blue:0 alpha:1],@"colorValue",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"RGB:0.75/0/0", @"@titleValue",[UIColor colorWithRed:0.75 green:0 blue:0 alpha:1],@"colorValue",nil],
nil
];
masterColorList = [NSArray arrayWithObjects:colorList,otherColorList,nil];
[masterColorList retain];
}
return self;
}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return masterColorList.count;
}/*
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[masterColorList objectAtIndex:section] count];
}
*/- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell = nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
cell.textColor = [[[masterColorList objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"colorValue"];
cell.selectedTextColor = [[[masterColorList objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"colorValue"];
cell.text = [[[masterColorList objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"titleValue"];
return cell;
}- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0)
{
return @"SDK Colors";
}
else if (section == 1)
{
return @"RGB Colors";
}
return 0;
}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheck];
}- (void)dealloc
{
[super dealloc];
[masterColorList release];
}- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}- (void)viewWillDisappear:(BOOL)animated
{
}- (void)viewDidDisappear:(BOOL)animated
{
}- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
中,
if (cell == nil)
少了一个等号建议以后写判断语句时,写成类似这样
if ( nil == cell)