2011-08-23 2 views
0

사용자가 액세서리 버튼을 클릭 할 때마다 변수 "resultStringID"를 두 번째 뷰 "DetailViewController"에 "RootViewController"에서 전달하는 방법이 필요합니다. accessoryButtonTappedForRowWithIndexPath 메서드에 대한 내 코드는 다음과 같습니다accessoryButtonTappedForRowWithIndexPath 메서드에서 인스턴스화 된 NSMutableString을 다른 뷰로 전달하는 방법

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { 



processSelected = [array objectAtIndex:indexPath.row]; 
//realstatusSelected = [processStatusarray objectAtIndex:indexPath.row]; 

//NSLog(@"Real selected status is %@", realstatusSelected); 
NSLog(@"combinedString at index is %@", processSelected); 


NSMutableString * resultStringID = [NSMutableString stringWithCapacity:processSelected.length]; 

NSScanner *scanner = [NSScanner scannerWithString:processSelected]; 
//define the allowed characters, here only all numbers are allowed 
NSCharacterSet *allowedChars = [NSCharacterSet characterSetWithCharactersInString:@"1234567890"]; 

while ([scanner isAtEnd] == NO) { 
    NSString *buffer; 
    if ([scanner scanCharactersFromSet:allowedChars intoString:&buffer]) { 
     [resultStringID appendString:buffer];  
    } else { 
     [scanner setScanLocation:([scanner scanLocation] + 1)]; 
    } 
} 

//Trim off the last 3 characters if the string is larger than 4 characters long 
if ([resultStringID length] > 4) 
    resultStringID = [resultStringID substringToIndex:[resultStringID length] - 3]; 

도움이 정말 감사드립니다! :)

답변

1

가장 쉬운 방법은 DetailViewController에 @property (copy) NSString *myString을 추가하는 것입니다. 그런 다음 새 컨트롤러를 만들 때 (바로 밀기 전에) newController.myString = resultStringID을 설정하십시오.

+0

고맙습니다. 그것은 간단하고 우아한 해결책이었다 :) –

0

이 DetailViewController를 선물/푸시 하시겠습니까?

DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle] andResultID:resultStringID]; 
[self.navigationController pushViewController:detailViewController animated:YES]; 
[detailViewController release]; 

당신이 그것을 밀어 싶다고 가정 : 일반적인 방법은, 언제나처럼 밀어 다음 DetailViewController

에 대한
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andResultId:(NSMutableString*)resultStringID 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) 
    { 
     // Do stuff with your resultStringID 
    } 
    return self; 
} 

을 자신의 init 메소드를 만들 것입니다. 반대로 DetailViewController가 이미 존재하고 이에 대한 참조가 있으면 문자열에 다른 @property (비 원자력, 보유)를 추가하면됩니다.

관련 문제