0

"tableColorName"문자열 개체를 선택한 셀로 변경하는 메서드를 만들려고합니다. tableData NSArray은 "red", "blue", "green"개체로 구성됩니다. 빨간색을 선택하는 경우 "tableColorName"문자열을 redColor, 파란색 인 경우 blueColor, 녹색 인 경우 greenColor으로 저장하려고합니다. 셀을 선택한 후 viewController를 루트로 되돌리려합니다. 나는 사전에 도움을 주셔서 감사합니다 :테이블 IOS에서 셀 선택

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath 
{ 
    int theRow = indexPath.row; 
    NSString *tableColorName; 
    tableColorName = [[NSString alloc] initWithString:([_tableData [theRow]  stringValue],@"Color")]; 
    [self.navigationController popToRootViewControllerAnimated:YES]; 
} 
+1

당신은 우리에게'cellForRowAtIndexPath' 메쏘드를 보여줄 수 있습니까 –

답변

1

이를 ::

NSArray *arr; 
NSString *tableColorName; // Use in AppDelegate 

- (void)viewDidLoad 
{ 
    arr = [[NSArray alloc] initWithObjects:@"Red", @"Green", @"Blue", nil]; 
} 

표보기 방법 : 다음

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    cell.title.text = [NSString stringWithFormat:@"%@", [arr objectAtIndex:indexPath.row]]; 
    return cell; 
} 

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    app.tableColorName = [NSString StringWithFormat:@"%@ Color", [arr objectAtIndex:indexPath.row]]; 
    [self.navigationController popToRootViewControllerAnimated:YES]; 
} 

, app.tableColorName 때마다 당신의 접근 시도 표시하려고합니다.

감사합니다.

+0

. 나는 그 앱을 사용할 필요가 없게되었다. 접두사는 ... 매력처럼 작동합니다. – ShadyBaker

0
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

    //do whatever with the selected cell. 
    //go back to the root 
} 
2
//first of all take one NSArray and 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
    self.colorNames = [[NSArray alloc] initWithObjects:@"Red", @"Green", 
        @"Blue", @"Indigo", @"Violet", nil]; 

} 

// Implement Table method 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  { 
    return [self.colorNames 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:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell. 
    [email protected]"Colors"; 

    UIImage *cellImage = [UIImage imageNamed:@"a.png"]; 
    cell.imageView.image = cellImage; 

    NSString *colorString = [self.colorNames objectAtIndex: [indexPath row]]; 

    cell.textLabel.text = colorString; 

    NSString *subtitle = [NSString stringWithString: @"All about the color "]; 
    subtitle = [subtitle stringByAppendingFormat:colorString]; 

    cell.detailTextLabel.text = subtitle; 

    return cell; 
} 

- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath  *)indexPath 
{ 
    int idx = indexPath.row; 
    obj.lbl.text=[@"You select "stringByAppendingString:[colorNames objectAtIndex:idx]]; 

    [self popToViewController animated:YES]; 
} 
+0

고마워요. 도와 주셔서 감사합니다. – ShadyBaker