簡體   English   中英

在第一個視圖控制器上的表視圖中顯示數組中的數據

[英]Display data from array in table view on first view controller

我試圖將一些XML數據解析為一個數組,然后在First View Controller上的Table View中顯示該數組。 您可以看到我已經將數據解析為所需的數據,然后將它們全部設置在數組中。 我只是不知道如何將其發送到GUI中的表視圖。 這是我的數組:

    NSString* mountPoint1 = [mountArray objectAtIndex: 11];
    NSString* mountPoint2 = [mountArray objectAtIndex: 17];
    NSString* mountPoint3 = [mountArray objectAtIndex: 23];
    NSString* mountPoint4 = [mountArray objectAtIndex: 29];
    NSString* currentSong1 = [mountArray objectAtIndex: 16];
    NSString* currentSong2 = [mountArray objectAtIndex: 22];
    NSString* currentSong3 = [mountArray objectAtIndex: 28];
    NSString* currentSong4 = [mountArray objectAtIndex: 34];
    NSString* listeners1 = [mountArray objectAtIndex: 14];
    NSString* listeners2 = [mountArray objectAtIndex: 20];
    NSString* listeners3 = [mountArray objectAtIndex: 26];
    NSString* listeners4 = [mountArray objectAtIndex: 32];
    NSLog(@"mountpoint1 should be dev = %@", mountPoint1);
    NSLog(@"All data = %@", mountArray);
    // First mount is 11
    NSLog(@"First mount point = %@", mountPoint1);
    NSLog(@"Currrent Song playing on mount Dev = %@", currentSong1);
    NSLog(@"Currrent listeners on mount Dev = %@", listeners1);
    NSLog(@"Second mount point = %@", mountPoint2);
    NSLog(@"Currrent Song playing on mount Metal = %@", currentSong2);
    NSLog(@"Currrent listeners on mount Metal = %@", listeners2);
    NSLog(@"Third mount point = %@", mountPoint3);
    NSLog(@"Currrent Song playing on mount OrienLive = %@", currentSong3);
    NSLog(@"Currrent listeners on mount OrienLive = %@", listeners3);
    NSLog(@"Fourth mount point = %@", mountPoint4);
    NSLog(@"Currrent Song playing on mount Rock = %@", currentSong4);
    NSLog(@"Currrent listeners on mount Rock = %@", listeners4);

您到底想做什么? 您可以執行以下操作:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //.. after initial setup
    NSInteger position = indexPath.row * 6;
    cell.mountLabel.text = [self.mountArray objectAtIndex:position + 11];
    cell.songLabel.text = [self.mountArray objectAtIndex:position + 16];
    cell.listenerLabel.text = [self.mountArray objectAtIndex:position + 14];
    //.. continue with other setup
}

這樣的事嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM