iphone - 尝试编辑单元格时 UITableView 崩溃

标签 iphone uitableview crash scroll

我有某种表单,其中包含表格 View 中的 5 个自定义单元格。这是代码:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;}

\- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}

\- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog(@"in here");
    static NSString *MyIdentifier = @"MyIdentifier";

    FreeSignupCell *cell = (FreeSignupCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        NSLog(@"shazam");
        cell = [[[FreeSignupCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;    
    }

    switch (indexPath.row) {
        case 0:
            NSLog(@"index 0");
            [cell setLabelContent:@"First Name"];
            //self.firstName = [cell getText];
            break;
        case 1:
            NSLog(@"index 1");
            [cell setLabelContent:@"Last Name"];
            //self.lastName = [cell getText];
            break;
        case 2:
            NSLog(@"index 2");
            [cell setLabelContent:@"Company (optional)"];
            //self.company = [cell getText];
            break;
        case 3:
            NSLog(@"index 3");
            [cell setLabelContent:@"Website (optional)"];
            [cell setText: @"http://"];
            //self.website = [cell getText];
            break;
        case 4:
            NSLog(@"index 4");
            [cell setLabelContent:@"E-mail"];
            //self.email = [cell getText];
            break;
        default:
            [cell setLabelContent:@"E-mail"];
    }

    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{  
    return 70.0;
}

问题是,当我编辑第一个字段时,快速滚动到最后一个字段,应用程序因 objc_mssend 错误而崩溃。

有什么想法吗?

最佳答案

另一个问题...这是我如何从页面获取数据

-(void) SignupAction {

//Fetching signup data from signup form
NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:0];
FreeSignupCell *cell = (FreeSignupCell *)[self.tableView cellForRowAtIndexPath:path];
self.firstName = [cell getText];

path = [NSIndexPath indexPathForRow:1 inSection:0];
cell = (FreeSignupCell *)[self.tableView cellForRowAtIndexPath:path];
self.lastName = [cell getText];

path = [NSIndexPath indexPathForRow:2 inSection:0];
cell = (FreeSignupCell *)[self.tableView cellForRowAtIndexPath:path];
self.company = [cell getText];

path = [NSIndexPath indexPathForRow:3 inSection:0];
cell = (FreeSignupCell *)[self.tableView cellForRowAtIndexPath:path];
self.website = [cell getText];

path = [NSIndexPath indexPathForRow:4 inSection:0];
cell = (FreeSignupCell *)[self.tableView cellForRowAtIndexPath:path];
self.email = [cell getText];

//JSON Dictionaries require parameters that are not null
if (self.firstName == nil) {
    self.firstName = @"";
}
if (self.lastName == nil) {
    self.lastName = @"";
}
if (self.company == nil) {
    self.company = @"";
}
if (self.website == nil) {
    self.website = @"";
}
if (self.email == nil) {
    self.email = @"";
}

当我按下页面上的“注册”按钮时,我只看到网站和电子邮件字段。发生的情况是,当我记录变量时,只有电子邮件和网站存在,其他的是@“”。发生了什么事?

关于iphone - 尝试编辑单元格时 UITableView 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1879616/

相关文章:

sql - 当我尝试执行简单查询时,Spark 3 失败

android - Android Studio:初始化ImageButton时崩溃

iphone - 在iPhone上实时录音/分析

jquery - 如何更改 pnotify Jquery 插件的默认宽度?

ios - NSFetchResultsController 显示虚假对象

ios - 分离 ViewController 和 UITableViewDataSource

iphone - 串联NSString不起作用

iphone - Core Data Cocoa 错误 1570。无法保存多个实体对象

ios - 如何获取显示uitableview单元格之前使用的消息标签的行数

iphone - 如何停止我不知道的NSTimer被释放