2012-12-20 3 views
1

저는 오늘 Objective-C와 XCode를 시작했습니다.Objective-C 배열을 통해 반복하여 화면에 인쇄

은 내가 문자열의 무리를 포함하는

NSMutableArray 

했습니다.

나는이처럼 내 배열을 통해 반복하고 있습니다 :

for (NSString *test in array) { 
} 

이제 어떻게 서로 아래에 서 화면에 각 값을 보여주기 위해 관리합니까? 어떤 UI 요소가 적절하고 그 요소를 실제로 어떻게 사용하는지 모르겠습니다. (아직 어떤 요소인지 모르겠지만 지금까지는 TextField, Button 및 Label에 대한 지식 만 보유하고 있습니다.)

답변

2

UILabel을 사용하고 numberOfLines을 0으로 설정하면 무한한 선이 나타납니다.

UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 200)]; 
myLabel.numberOflines = 0; 
[self.view addSubview:myLabel]; 

NSString *testText = @""; 
for (NSString *test in array) { 
    testText = [testText stringByAppendingFormat:@"%@\n", text]; 
} 
myLabel.text = testText; 
+0

이동 중에 행의 금액을 편집 할 수 있습니까? 따라서 배열을 반복 할 때마다 새로운 행이 추가됩니까? –

+0

그건 필요하지 않습니다. 크기를 만들려면 레이블의 프레임을 설정해야합니다. –

1

당신은 더 나은 귀하의 [배열 계산] 될 것 인덱스 경로에서 행의 jQuery과 수 있도록; 그리고 각 셀에 display [array objectAtIndex : indexPath.row]; 전체 코드가 필요한 경우

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return array.count; 
} 
- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 
             reuseIdentifier:CellIdentifier]; 
    } 

    cell.text = [array objectAtIndex:indexPath.row]; 
    return cell; 
} 
+0

나는 코드 예제를 절대적으로 좋아할 것입니다. –

관련 문제