내비게이션보기 iPhone 앱이 있습니다. 나는 'name'NSString과 'weight'NSNumber를 가진 간단한 객체를 만들었다. 이 응용 프로그램은 셀을로드 할 때 충돌을 계속합니다. 좀비가 아니어야하는 좀비 오브젝트
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
factor *toAdd = [factors objectAtIndex:indexPath.row];
cell.textLabel.text = toAdd.name;
cell.detailTextLabel.text = [toAdd.weight stringValue];
//^crashes here...
// stringByAppendingString:@"%"];
return cell;
}
내가의 NSNumber에 stringValue 메소드를 호출 할 때 콘솔에서 "할당이 해제 된 인스턴스에 보낸 메시지"를 얻을 : 여기에 방법이다. 나는 이것이 왜 일어나고 있는지 이해하지 못한다. 위의 줄은 이름에 액세스하는 데 아무런 문제가 없으며 [릴리스] 문이 없습니다.
당신에게
편집 감사합니다 가 여기 내 요소의 초기화 방법입니다. 나는 이중 체크를하고 무게는 (유지, 비 원자)이며, 구현과 마찬가지로 이름과 같다. 성공적으로 name
속성에 액세스 할 수 있다는
- (id) init{
if(self = [super init])
{
weight = [NSNumber numberWithInt:10];
name = @"Homework";
}
return self;
}
'// stringByAppendingString : @ "%"]; '? – Joe
당신은 당신의 방법 목욕 소금을 먹이고 있습니까? –
무게는 백분율 값이므로 내 문자열의 끝에 '%'기호가 있어야합니다. 나는 [NSNumber stringValue] 문제를 먼저 해결하기 위해 주석 처리했다. 그런 다음 주석을 제거하겠다. – gamda