2009-08-14 7 views
0

저는 Objective-C를 처음 사용하여 도움이 필요합니다!버튼이있는 UIView가있는 UIPageControl

그물에서 찾을 수있는 "PageControl"예제를 따르고 있습니다. NIB의보기에 단추를 추가하고 구현이 아래에있는 동작을 연결했습니다. 여기

은 뷰 컨트롤러에 대한 나의 정의는 페이지 컨트롤에 표시되는 :

 
//ContactCardViewController.h 
@interface ContactCardViewController : UIViewController 
{ 
    int pageNumber; 
    NSMutableString *s; 
} 


//ContactCardViewController.m implementation 

- (id)initWithPageNumber:(int)page { 
    if (self = [super initWithNibName:@"ContactCardViewController" bundle:nil]) { 
     s = [[NSString alloc] initWithFormat:@"page: %d", page];    
    } 
    return self; 
} 


- (id)initWithString:(NSDictionary *)_s { 
    if (self = [super initWithNibName:@"ContactCardViewController" bundle:nil]) { 
     NSMutableString *t = [[NSMutableString alloc] initWithString:_s]; 
     s = t; 
    } 
    return self; 
} 


-(IBAction)callOrAddToContacts:(id)sender 
{ 
    jobtitleLabel.text = s; 
} 


//AppDelegate.m 
//in delegate that loads the scroll view with the view for the current page: 

- (void)loadScrollViewWithPage:(int)page { 
//init the view this way the page: and the correct page number is displayed 
    controller = [[ContactCardViewController alloc] initWithPageNumber:page ]; 

//init the view this way, the value of the first person is always displayed 
    controller = [[ContactCardViewController alloc] initWithString:[[self.allNames objectAtIndex:page] objectForKey:@"firstname"]]; 

} 


뷰가 initWithString로 만든 후, 버튼의 조치에 대해서만 값을 통해 액세스되는 이유 때 이해 제발 도와주세요 목록의 첫 번째 사람이 항상 반환됩니다. initWithPageNumber를 사용하여 뷰를 초기화 할 때 올바른 값을가집니다. 페이지 : X

답변

0

InitWithString 코드에서 문자열이 아닌 사전을 전달합니다.

- (id)initWithString:(NSDictionary *)_s { 
    if (self = [super initWithNibName:@"ContactCardViewController" bundle:nil]) { 
     NSMutableString *t = [[NSMutableString alloc] initWithString:_s]; 
     s = t; 
    } 
    return self; 
}

당신은있는 NSDictionary의 인스턴스에 ...있는 NSString에 그 변경 또는 인 NSMutableString을 변경할 수 있습니다. 둘 중 하나.

+0

감사합니다. 복사/붙여 넣기 오류.

 - (id)initWithString:(NSMutableString *)_s { 
같은 문제가 있습니다. 읽기를 시도 할 때 액션 내의 코드는 컨트롤이 현재있는 페이지와 관계없이 항상 목록의 첫 번째 값을 읽습니다. – radiofrequency

0

발견 된 문제는 plist 파일에 있습니다. 코드는 괜찮습니다.