UITableView没有完全滚动然后崩溃

时间:2013-12-07 08:20:19

标签: ios objective-c uitableview

(iOS 7)(Xcode 5.0.2)我有一个UITableView,在单元格中是按钮,用不同的标题数组重新加载表格,如文件系统。它有三个级别,用户,视频和统计数据。当我点击一个用户时,它会在我从视频数组中单击的行的索引处加载数组,并为统计信息添加相同的数组。它加载正常,然后我选择用户。它向我显示了视频列表,但我无法向下滚动以查看页面之外的视频。然后,如果我点击任何视频,应用程序崩溃。以下是我的相关方法:

-(IBAction)menu{
    x --;
if(x == 0){
    x ++;
} else if(x == 1){
    [self.titleLabel setTitle:@"Users"];
    [back setEnabled:NO];
} else if(x == 2){
    [self.titleLabel setTitle:@"Videos"];
} else if(x == 3){
    [self.titleLabel setTitle:@"Stats"];
}
[self.table reloadData];
}
-(IBAction)clicked:(UILambdaButton *)sender{
x ++;
if(x == 1){
    [self.titleLabel setTitle:@"Users"];
} else if(x == 2){
    [self.titleLabel setTitle:@"Videos"];
    [back setEnabled:YES];
    y = sender.row;
} else if(x == 3){
    [self.titleLabel setTitle:@"Stats"];
    [back setEnabled:YES];
    z = sender.row;
} else if(x == 4){
    x --;
}
[self.table reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSInteger rows;
if(x == 1){
    rows = [users count];
} else if(x == 2){
    rows = [[videos objectAtIndex:y] count];
} else {
    rows = [[[stats objectAtIndex:y] objectAtIndex:z] count];
}
return rows;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
UILambdaButton *button = [[UILambdaButton alloc]initWithFrame:cell.frame];
if(x == 1){
    [button setTitle:[users objectAtIndex:indexPath.row] forState:UIControlStateNormal];
} else if(x == 2){
    [button setTitle:[[videos objectAtIndex:y] objectAtIndex:indexPath.row] forState:UIControlStateNormal];
} else if(x == 3){
    [button setTitle:[[[stats objectAtIndex:y] objectAtIndex:z] objectAtIndex:indexPath.row] forState:UIControlStateNormal];
}
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchDown];
cell.accessoryView = button;
button.row = indexPath.row;
return cell;
}

UILambdaButton类与UIButton相同,但它有一个属性行,它是一个整数。菜单方法是附加到我的后退按钮上升到一个级别的方法。当应用程序崩溃时,它会记录以下错误:

2013-12-07 08:08:23.776 Lambda Does Youtube[4574:60b] -[__NSCFString count]: unrecognized selector sent to instance 0x155fae10
2013-12-07 08:08:23.780 Lambda Does Youtube[4574:60b] *** Terminating app due to  uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString count]: unrecognized selector sent to instance 0x155fae10'
*** First throw call stack:
(0x2f16ff4b 0x394ff6af 0x2f1738e7 0x2f1721cb 0x2f0c14d8 0x150fab 0x319b7361 0x319b9585 0x319b94dd 0x319b90d9 0x150e1f 0x31917713 0x319176b3 0x31917691 0x3190311f 0x3191f8ad 0x318dabcb 0x31912419 0x31911dbf 0x318e779d 0x318e5fa3 0x2f13b183 0x2f13a653 0x2f138e47 0x2f0a3c27 0x2f0a3a0b 0x33d82283 0x31947049 0x17c5b7 0x39a07ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

EDIT ---------------------------------------------- --------------------------------------- 我的Users数组是一个字符串数组,我的Videos数组是一个数组数组,每个数组都包含字符串,我的stats数组是一个数组数组的数组,每个数组都包含字符串。

2 个答案:

答案 0 :(得分:2)

检查行值

[users count]
[[videos objectAtIndex:y] count]
[[[stats objectAtIndex:y] objectAtIndex:z] count]

问题高于一个值返回NSString它不返回NSArryNSString没有计数属性

答案 1 :(得分:0)

数组是否使用retain in:NSArray * array = [[NSArray arrayWithObjects:@“”,nil] retain];