Trong ứng dụng iphone Tôi cần truyền một số giá trị cho đối tượng viewcontroller mới trong khi nó tạo từ phương thức trong lớp viewcontroller khác để tôi có thể khởi tạo giá trị đó trong (id) initWithNibName: method của new viewcontroller Tôi có thể tải các giá trị đó trong phương thức viewdidLoad.Tham số truyền bằng initWithNibName:
những gì tôi muốn biết là làm cách nào để chuyển các giá trị (tham số) tới hàm tạo (initWithNibName) của một trình điều khiển xem mới Đối tượng như hàm nạp quá tải trong java cho tôi một số ví dụ mã chỉ hiển thị cách initWithNibName gọi với tham số bổ sung và làm thế nào để lấy lại chúng trong mới được tạo ra đối tượng Thanks ...
trả lời
đây là cách tôi giải quyết vấn đề "Quan sát là một đối tượng wit h thuộc tính" trong ViewControllor.h tôi đặt
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil set:(Observation *)observation;
trong tập tin ViewControllor.m tôi đặt
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil set:(Observation *)observation{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization on passed parameter observation object
draftObservation = observation;
}
return self;
}
sau đó tôi gọi nó theo cách này trong lớp khác
ObsevationListView *obsevationListView = [[ObservationViewControllor alloc]
initWithNibName:@"ObservationViewControllor"
bundle:nil set:observer];
[self.navigationController pushViewController:obsevationListView animated:YES];
hoạt động tốt. Tôi rất vui nếu có ai có được sự giúp đỡ từ này
Rất đẹp ... Tôi chính xác muốn điều này ... Cảm ơn một tấn. – viral