저는 Person이라는 클래스가 있고이 클래스에는 PersonName 속성이 있습니다.목표 C - NSMutableArray 및 NSTableView 문제
MutableArray MyUserInfoArr
에는 많은 Person 개체가 포함되어 있습니다.
각 PersonName을 TableView의 셀에 나열하고 싶습니까? 어떻게해야합니까? 미리 감사드립니다.
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
Person *myPerson = [myUserInfoArr objectAtIndex:indexPath.row];
cell.textLabel.text = myPerson.DisplayName;
NSLog(@"abc %i",indexPath.section);
}
이
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
Person *myPerson;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
NSString *cellValue = [myUserInfoArr objectAtIndex:indexPath.row];
cell.text = cellValue;
내 코드, 그것은 실행하지만, 그냥 myUserInfoArr의 마지막 개체 사람의 속성 Person.DisplayName을 반환합니다. 그것을 고치는 방법? 첫 번째는 섹션 내에서 항목의 인덱스, 섹션 인덱스,
Person *person = [MyUserInfoArr objectAtIndex:[indexPath indexAtPosition:1]];
cell.textLabel.text = person.PersonName;
indexPath 두 개의 인덱스를 포함
하지만 myUserInfoArr에는 Person 클래스의 많은 객체가 포함되어 있기 때문에 로직의 [myUserInfoArr objectAtIndex : indexPath.row]는 NSString을 반환하지 않습니다. – ThyPhuong