2011-02-08 22 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 2011-02-08 05:37:50

+0

所有3行中的元素,我想這樣 – 2011-02-08 05:56:58

+0

請確保你已經設置了表的數據源和委託。然後按照羅賓的指示。謝謝, – GameLoading 2011-02-08 06:17:35

回答

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中有兩個值,但我想在一行中顯示這兩個值,然後在下一個單行中顯示下兩個值,你知道嗎? – 2011-02-08 06:02:02

0

@Veer使用這樣的

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

或類似這樣的東西。如果您向我們展示myArrayNew中的內容類型,那麼我們可以幫助您更多。

編輯:這只是一個例子不是實際的答案。

0

您必須將值存儲在一個更array..and第二數組對象可以分配給一個字符串..

相關問題