UITableView is crashing when trying to edit cell
I am having some form in that is consisting of 5 custom cells in a table view. Here is the code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;}
\- (NSInteger)tableView:(UITableView *)ta开发者_如何学PythonbleView 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;
}
The problem is that when I edit first field, that scroll quickly to the last one, app crashes with objc_mssend error.
Any ideas?
Another issue... Here is how I am getting data from the page
-(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 = @"";
}
When I am pressing SignUp button on the page I only see website and email fields. What happens is that when I log variables, only email and website are there, other ones are @"". What is happening?
When the FreeSignupCell goes away (say because it scrolled off the top or bottom, or gets reused), and the getText from that destructed cell goes away and gets [text release];'d on you, what happens to your self.firstName, self.lastName, self.company, self.website, and self.email that now refers to a string object that was free()'d?
I think you should use [[cell getText] retain]; instead.
精彩评论