我正在創建一個iPhone遊戲,它將調用一個通用的新聞源並隨機應用一個股票,影響股價與低中或高增加/減少。有人建議我使用平行陣列來解決這個問題。這是最好的方法嗎?有沒有人得到一個有用的鏈接教程如何做到這一點?並行數組
我有一個簡單的數組設置。但我是x-code的新手,我需要編寫一些代碼來調用數組中的項目。
#import "NewsFeedViewController.h"
@interface NewsFeedViewController()
@end
@implementation NewsFeedViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//Setup NSArray
items = [[NSArray alloc] initWithObjects:@"Galaxy", @"Redbull", @"Boost", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
return items.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.textLabel.text = [items objectAtIndex:indexPath.row];
return cell;
}
@end
我猜想似乎都在旁邊我創建的tableView對方?這是一個好開始,謝謝。從數組中顯示隨機單元的困難過程? – 2013-03-06 11:39:36