Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 调用“时,如何解决UITableView中的SIGABRT?”;删除RowsatindExpaths“;_Objective C_Ios5_Xcode4.2 - Fatal编程技术网

Objective c 调用“时,如何解决UITableView中的SIGABRT?”;删除RowsatindExpaths“;

Objective c 调用“时,如何解决UITableView中的SIGABRT?”;删除RowsatindExpaths“;,objective-c,ios5,xcode4.2,Objective C,Ios5,Xcode4.2,我是IOS开发的初学者。我用数据构建了一个UITableView, 但在最后一行,它不是一个数据行,称为“加载更多项”。(此显示名称不好。我将在稍后更改它,可能是在我修复此问题后) “加载更多项目”包括两个功能: 选择最后一行时,此表将自动追加4行。 再次选中时,将删除这4行。一次又一次 但当我第二次选择“加载更多项目”时,它显示“程序接收信号:'SIGABRT'” 我在没有ARC的情况下,在xcode 4.2.1 ios5 SDK中构建了这个xcode项目,但在运行时出现了一个问题。以下代码给

我是IOS开发的初学者。我用数据构建了一个UITableView, 但在最后一行,它不是一个数据行,称为“加载更多项”。(此显示名称不好。我将在稍后更改它,可能是在我修复此问题后)

“加载更多项目”包括两个功能: 选择最后一行时,此表将自动追加4行。 再次选中时,将删除这4行。一次又一次

但当我第二次选择“加载更多项目”时,它显示“程序接收信号:'SIGABRT'”

我在没有ARC的情况下,在xcode 4.2.1 ios5 SDK中构建了这个xcode项目,但在运行时出现了一个问题。以下代码给出:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

return 1;}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [posts count] + 1;}

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
static NSString *postCellId = @"postCell";
static NSString *moreCellId = @"moreCell";
UITableViewCell *cell = nil;

NSUInteger row = [indexPath row];
NSUInteger count = [posts count];

if (row == count) {
    NSLog(@"%@ -  indexPath : %d",NSStringFromSelector(_cmd), [indexPath row]);
    
    cell = [tableView dequeueReusableCellWithIdentifier:moreCellId];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] 
                 initWithStyle:UITableViewCellStyleDefault 
                 reuseIdentifier:moreCellId] autorelease];
    }
    
    cell.textLabel.text = @"Load more items...";
    cell.textLabel.textColor = [UIColor blueColor];
    cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
    
    
} else {

    cell = [tableView dequeueReusableCellWithIdentifier:postCellId];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] 
                 initWithStyle:UITableViewCellStyleSubtitle 
                 reuseIdentifier:postCellId] autorelease];
    }

    Post *currentPost = [posts objectAtIndex:row];
    cell.textLabel.text = [currentPost postTitle];
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    
    cell.detailTextLabel.text = [currentPost postDescr];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:10];
}

return cell;}

- (void)tableView:(UITableView *)tableView 
               didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"%@",NSStringFromSelector(_cmd));

NSUInteger row = [indexPath row];
NSUInteger count = [posts count];

if (row == count) {
    
    if(SIMPLE_FLAG_INT==0){
        NSArray *newPosts = [feed detailPosts];
        NSUInteger newCount = [newPosts count];
        
        if (newCount) {
            
            [self.posts addObjectsFromArray:newPosts];
            [newPosts release];
            
            NSMutableArray *insertIndexPaths = [NSMutableArray array];
            for (NSUInteger item = count; item < count + newCount; item++) {
                
                [insertIndexPaths addObject:[NSIndexPath indexPathForRow:item 
                                                               inSection:0]];
            }

                
            [self.tableView beginUpdates];  
            [self.tableView insertRowsAtIndexPaths:insertIndexPaths 
                                      withRowAnimation:UITableViewRowAnimationFade];
            [self.tableView endUpdates];
            
            SIMPLE_FLAG_INT = 1;
            
            
            [self.tableView scrollToRowAtIndexPath:indexPath 
                                  atScrollPosition:UITableViewScrollPositionNone animated:YES];
            
           
        }
    }else{
        SIMPLE_FLAG_INT = 0;

        NSLog(@" ==> %d num of row in section 0 ",[self tableView:self numberOfRowsInSection:0]);


        NSMutableArray *deleteIndexPaths = [NSMutableArray array];
        [deleteIndexPaths addObject:[NSIndexPath indexPathForRow:6   inSection:0]];
        [deleteIndexPaths addObject:[NSIndexPath indexPathForRow:5   inSection:0]];
        [deleteIndexPaths addObject:[NSIndexPath indexPathForRow:4   inSection:0]];    
        [deleteIndexPaths addObject:[NSIndexPath indexPathForRow:3   inSection:0]];
        
        
        [self.tableView beginUpdates];
        // Error here, SIGABRT, EXC_BAD_INSTRUCTION
        [self.tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];  
        [self.tableView endUpdates];               
    }
    
    NSIndexPath *selected = [self.tableView indexPathForSelectedRow];
    NSLog(@"%@ - indexPathForSelectedRow(selected row): %d",NSStringFromSelector(_cmd), [selected row]);
    if (selected) {
        [self.tableView deselectRowAtIndexPath:selected animated:YES];
    }
    
} else {

    PostViewController *postController = [[PostViewController alloc] 
                                          initWithNibName:@"PostView" 
                                          bundle:nil];
    postController.post = [posts objectAtIndex:row];

    [[self navigationController] pushViewController:postController 
                                           animated:YES];
    [postController release];
} }
-(NSInteger)节数表视图:(UITableView*)表视图{
返回1;}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
return[posts count]+1;}
-(UITableView单元格*)表格视图:(UITableView*)表格视图
CellForRowatineXpath:(NSIndexPath*)indexPath{
静态NSString*postCellId=@“postCell”;
静态NSString*moreCellId=@“moreCell”;
UITableViewCell*单元格=nil;
NSUTEGER行=[indexPath行];
NSU整数计数=[posts计数];
如果(行==计数){
NSLog(@“%@-indepath:%d”,NSStringFromSelector(_cmd),[indepath行];
cell=[tableView dequeueReusableCellWithIdentifier:moreCellId];
如果(单元格==nil){
单元格=[[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:moreCellId]自动释放酶];
}
cell.textlab.text=@“加载更多项…”;
cell.textlab.textColor=[UIColor blueColor];
cell.textlab.font=[UIFont boldSystemFontOfSize:14];
}否则{
单元格=[tableView dequeueReusableCellWithIdentifier:postCellId];
如果(单元格==nil){
单元格=[[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
重用标识符:PostEllid]自动释放];
}
Post*currentPost=[posts对象索引:行];
cell.textlab.text=[CurrentPostTitle];
cell.textlab.font=[UIFont systemFontOfSize:14];
cell.detailTextLabel.text=[currentPost postDescr];
cell.detailTextLabel.font=[UIFont systemFontOfSize:10];
}
返回单元格;}
-(void)tableView:(UITableView*)tableView
DidSelectRowatineXpath:(NSIndexPath*)indexPath{
NSLog(@“%@”,NSStringFromSelector(_cmd));
NSUTEGER行=[indexPath行];
NSU整数计数=[posts计数];
如果(行==计数){
if(简单标志=0){
NSArray*newPosts=[feed detailPosts];
NSU整数newCount=[newPosts count];
如果(新计数){
[self.posts addObjectsFromArray:newPosts];
[newPosts-release];
NSMutableArray*insertIndexPaths=[NSMutableArray];
对于(整数项=计数;项<计数+新计数;项++){
[InsertInExpaths addObject:[nsInExpathInExpathForRow:item
不确定:0]];
}
[self.tableView开始更新];
[self.tableView insertRowsAtIndexPaths:insertIndexPaths
withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
简单_标志_INT=1;
[self.tableView ScrollToRowatineXpath:indexPath
atScrollPosition:UITableViewScrollPosition无动画:是];
}
}否则{
简单_标志_INT=0;
NSLog(@“=>%d节0中的行数,[self tableView:self numberofrowsinssection:0]);
NSMutableArray*DeleteIndexPath=[NSMutableArray];
[DeleteIndexPath添加对象:[NSIndexPath indexPathForRow:6第0节];
[DeleteIndexPath添加对象:[NSIndexPath indexPathForRow:5第0节];
[DeleteIndexPath添加对象:[NSIndexPath indexPathForRow:4第0节];
[DeleteIndexPath添加对象:[NSIndexPath indexPathForRow:3第0节];
[self.tableView开始更新];
//此处出错,SIGABRT,EXC\u错误\u指令
[self.tableView deleteRowsAndExpaths:deleteIndexPaths with RowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
}
NSIndexPath*selected=[self.tableView indexPathForSelectedRow];
NSLog(@“%@-indexPathForSelectedRow(选定行):%d”,NSStringFromSelector(_cmd),[selected row]);
如果(选定){
[self.tableView取消行索引路径:所选动画:是];
}
}否则{
PostViewController*postController=[[PostViewController alloc]
initWithNibName:@“PostView”
束:零];
postController.post=[posts objectAtIndex:row];
[[self-navigationController]推送视图控制器:后控制器
动画:是];
[后控制器释放];
} }
以下是控制台输出:

2012-03-28 02:20:22.059进料器[4577:bf03]表格视图:didSelectRowAtIndexPath:

2012-03-28 02:20:22.064进料器[4577:bf03]表格视图:DIDSelectRow索引路径:-indexPathForSelectedRow(所选行):7

2012-03-28 02:20:23.600进料器[4577:bf03]表格视图:didSelectRowAtIndexPath:

2012-03-28 02:20:23.601进料器[4577:bf03]==>0段中8行

当前语言:自动;当前目标-c

2012-03-28 02:21:05.756馈线[4577:bf03]***在-[UITableView\u endCellAnimationsWithContext:],/SourceCache/UIKit\u Sim/UIKit-1448.89/UITableView.m:995中断言失败

2012-03-28 02:21:05.758馈线[4577:bf03]***因未捕获而终止应用程序,除非
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

return 1;}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [posts count] + 1;}

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
static NSString *postCellId = @"postCell";
static NSString *moreCellId = @"moreCell";
UITableViewCell *cell = nil;

NSUInteger row = [indexPath row];
NSUInteger count = [posts count];

if (row == count) {
    NSLog(@"%@ -  indexPath : %d",NSStringFromSelector(_cmd), [indexPath row]);
    
    cell = [tableView dequeueReusableCellWithIdentifier:moreCellId];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] 
                 initWithStyle:UITableViewCellStyleDefault 
                 reuseIdentifier:moreCellId] autorelease];
    }
    
    cell.textLabel.text = @"Load more items...";
    cell.textLabel.textColor = [UIColor blueColor];
    cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
    
    
} else {

    cell = [tableView dequeueReusableCellWithIdentifier:postCellId];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] 
                 initWithStyle:UITableViewCellStyleSubtitle 
                 reuseIdentifier:postCellId] autorelease];
    }

    Post *currentPost = [posts objectAtIndex:row];
    cell.textLabel.text = [currentPost postTitle];
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    
    cell.detailTextLabel.text = [currentPost postDescr];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:10];
}

return cell;}

- (void)tableView:(UITableView *)tableView 
               didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"%@",NSStringFromSelector(_cmd));

NSUInteger row = [indexPath row];
NSUInteger count = [posts count];

if (row == count) {
    
    if(SIMPLE_FLAG_INT==0){
        NSArray *newPosts = [feed detailPosts];
        NSUInteger newCount = [newPosts count];
        
        if (newCount) {
            
            [self.posts addObjectsFromArray:newPosts];
            [newPosts release];
            
            NSMutableArray *insertIndexPaths = [NSMutableArray array];
            for (NSUInteger item = count; item < count + newCount; item++) {
                
                [insertIndexPaths addObject:[NSIndexPath indexPathForRow:item 
                                                               inSection:0]];
            }

                
            [self.tableView beginUpdates];  
            [self.tableView insertRowsAtIndexPaths:insertIndexPaths 
                                      withRowAnimation:UITableViewRowAnimationFade];
            [self.tableView endUpdates];
            
            SIMPLE_FLAG_INT = 1;
            
            
            [self.tableView scrollToRowAtIndexPath:indexPath 
                                  atScrollPosition:UITableViewScrollPositionNone animated:YES];
            
           
        }
    }else{
        SIMPLE_FLAG_INT = 0;

        NSLog(@" ==> %d num of row in section 0 ",[self tableView:self numberOfRowsInSection:0]);


        NSMutableArray *deleteIndexPaths = [NSMutableArray array];
        [deleteIndexPaths addObject:[NSIndexPath indexPathForRow:6   inSection:0]];
        [deleteIndexPaths addObject:[NSIndexPath indexPathForRow:5   inSection:0]];
        [deleteIndexPaths addObject:[NSIndexPath indexPathForRow:4   inSection:0]];    
        [deleteIndexPaths addObject:[NSIndexPath indexPathForRow:3   inSection:0]];
        
        
        [self.tableView beginUpdates];
        // Error here, SIGABRT, EXC_BAD_INSTRUCTION
        [self.tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];  
        [self.tableView endUpdates];               
    }
    
    NSIndexPath *selected = [self.tableView indexPathForSelectedRow];
    NSLog(@"%@ - indexPathForSelectedRow(selected row): %d",NSStringFromSelector(_cmd), [selected row]);
    if (selected) {
        [self.tableView deselectRowAtIndexPath:selected animated:YES];
    }
    
} else {

    PostViewController *postController = [[PostViewController alloc] 
                                          initWithNibName:@"PostView" 
                                          bundle:nil];
    postController.post = [posts objectAtIndex:row];

    [[self navigationController] pushViewController:postController 
                                           animated:YES];
    [postController release];
} }