2013-03-06 3 views
2

나는 일반 Newsfeed를 호출하고 무작위 공유로 적용하여 주가가 낮은 중간 증가 또는 감소하는 아이폰 게임을 만들고 있습니다. 병렬 배열을 사용하여이 문제를 해결할 것을 제안했습니다. 그게 최선의 방법인가요? 그리고 튜토리얼에 대한 유용한 링크가있는 사람이 있습니까?병렬 어레이

간단한 배열 설정이 있습니다. 하지만 x 코드가 처음인데 배열에서 항목을 호출하도록 코딩 된 코드를 가져와야합니다.

#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 

답변

1

당신이 병렬 배열을 찾는 경우는, 다음이 예입니다

NSArray *[email protected][@"A",@"B",@"C",@"D"]; 
NSArray *[email protected][@"Apple",@"BlackBerry",@"Cognizant",@"Dell"]; 


for (NSInteger i=0; i<alphabets.count; i++) { 
    NSLog(@"%@ for %@",alphabets[i],words[i]); 
} 

두 배열은 1-1 매핑으로 관련되어 있음을 분명히하고 반복하면서 것, 내가 사용 기록과 일치하는 동일한 색인.

+0

:

샘플 프로젝트 링크는 아래이지만,이 코드의 고기인가? 그게 좋은 출발이야, 고마워. 어레이의 무작위 세포를 어려운 과정으로 표시하고 있습니까? –

0

방금 ​​관련이없는 질문에 대답했지만, 내가 만든 프로젝트는 TableView의 데이터 소스로 3 개의 배열을 사용합니다. 내가 그 내가 만든있는 tableView 서로 함께 모두 나타납니다 추정 https://dl.dropbox.com/u/3660978/UniversalTableView.zip

-(void)populateArrays { 
    // New literal syntax of interacting with Arrays. 
    namesArray = @[@"Homer Simpson",@"Marge Simpson",@"Bart Simpson",@"Lisa Simpson",@"Maggie Simpson",@"Mr. Burns", 
        @"Principal Skinner",@"Krusty the Clown"]; 

    descriptionsArray = @[@"Homer is a lazy, but also a funny father", 
          @"Marge is smart, but not smart enough to not marry Homer lol", 
          @"Bart is just a smart-alec, but he is really funny too", 
          @"Lisa is the smartest one and the brunt of most jokes", 
          @"Maggie is just the baby of the family", 
          @"Mr. Burns is Homer's boss and evil too", 
          @"Principal Skinner is Bart and Lisa's principal at school", 
          @"Krusty is always clowning around (not really that funny though)"]; 

    imagesArray = @[@"homer.jpg",@"marge.jpg",@"bart.jpg",@"lisa.jpg",@"maggie.jpg",@"burns.jpg", 
        @"skinner.jpg",@"krusty.jpg"]; 
} 


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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"MyCustomCell"; 
    CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    // Configure the cell... 
    cell.customLabel.text = [namesArray objectAtIndex:indexPath.row]; 
    cell.customTextView.text = [descriptionsArray objectAtIndex:indexPath.row]; 
    cell.customImageView.image = [UIImage imageNamed:[imagesArray objectAtIndex:indexPath.row]]; 


    return cell; 
}