2011-02-08 4 views
1

은 내가 UITable이를 저장할 배열을 가지고 있지만 표시되지 않은, 내 코드는배열이 다른 객체의 다른 배열을 저장하는 동안 어떻게 NSMutableArray를 테이블에 저장할 수 있습니까?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return 1; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return [myArrayNew count]; 
} 


// 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:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell... 
    NSString *cellValue = [myArrayNew objectAtIndex:indexPath.row]; 
    cell.textLabel.text = cellValue; 
    return cell; 
} 

이며,이 배열은 당신에게 그리고 다른 배열, 단일하지 객체,

+0

어떻게하면 배열 값 배열을 UITableview에 표시하겠습니까? – KingofBliss

+0

한 행에 3 개의 요소가 모두 포함되어 있으므로이 테이블에 데이터 소스와 위임을 설정했는지 확인하십시오. –

+0

로빈의 지시를 따르십시오. 덕분에, – GameLoading

답변

0

을 가지고있다 다르게 코드해야합니다.

[myArrayNew objectAtIndex:indexPath.row]; 

은 문자열이 아닌 개체 배열을 반환합니다.

는 편집 :

당신은 배열의 배열을 표시하는 구분의 tableview를 사용할 수 있습니다.

그래서 그 코드는

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return [myArrayNew count]; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return [[myArrayNew objectAtIndex:section]count]; 
} 


// 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:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell... 
    NSString *cellValue = [[myArrayNew objectAtIndex:section]objectAtIndex:indexPath.row]; 
    cell.textLabel.text = cellValue; 
    return cell; 
} 
+0

NSMutableArray에 두 개의 값을 가졌지 만 하나의 단일 행에 두 값을 표시하고 다음 단일 행에 다음 두 값을 표시하려고합니다. –

+0

오류가 발생했습니다 '섹션'이 선언되지 않았습니다. 이제이 섹션은 무엇입니까? –

+0

죄송합니다. indexPath.section으로 변경하십시오. – KingofBliss

0

@Veer이 같은이

NSArray *cellArray = [myArrayNew objectAtIndex:indexPath.row]; 
NSString *cellValue = [cellArray objectAtIndex:indexPath.row]; 
cell.textLabel.text = cellValue; 
return cell; 

이나 뭐 같은 것을 사용하여 다음과 같이. myArrayNew에 어떤 유형의 컨텐츠가 있는지 알려 주시면 더 많이 도와 드리겠습니다.

편집 :이 예는 실제 답변이 아닙니다.

+0

cellArray count가 myArrayNew count보다 작 으면 충돌이 발생합니다. 이 경우 인덱스가 바운드 될 수 있습니다. – KingofBliss

+0

예, 알고 있습니다. 그러나 이것은 실제 솔루션이 아닌 단지 예일뿐입니다. – Robin

0

더 많은 배열에 값을 저장해야하고 .. 문자열에 할당 할 수있는 두 번째 배열 객체 ..

+0

선생님 NSMutableArray, NSString, 할당 된 있지만 여전히 문제가 내 테이블의 단일 행에 내 NSMutableArray 두 값을 모두 표시 할 수 없다는 동일합니다 –

관련 문제