0

ビュー間でカスタム クラスを渡そうとしています。そのクラスのプロパティを設定しましたが、プロパティにアクセスすると、属性は常に null を返します。

firstview.m:

- (void)initNextEventView{
NSDate *eventDate = [eventDatePicker date];
NSString *eventName = eventNameTextfield.text;

LocateEventViewController *locView = [[LocateEventViewController alloc]init];
locView.eventDTO.name = eventName;
locView.eventDTO.date = eventDate;

[[self navigationController] pushViewController:locView animated:YES];
}

LocateEventVC.h (2. ビュー):

@interface LocateEventViewController : UIViewController<MKMapViewDelegate, UISearchBarDelegate, BSForwardGeocoderDelegate>
@property (strong, nonatomic) IBOutlet UIImageView *imageBackground;
@property (strong, nonatomic) EventDTO *eventDTO;

そのため、 eventDTOの属性をログに記録すると、null が返されます。

どんな助けでも素晴らしいでしょう

編集1(2.ビュー): それが私が記録する方法です:

NSLog(@"name on 2. view: %@", eventDTO.name);
self.eventDTO.place = tmpEventPlace;
// init friends view!

//passing to next view
EventMembersViewController *members = [[EventMembersViewController alloc]init];

members.eventDTO = self.eventDTO;

EventDTO.h

@interface EventDTO : NSObject

@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) UserDTO * creatorIsAppUser;
@property (nonatomic, retain) ContactDTO * creatorIsNotAppUser;
@property (nonatomic, retain) NSString * description;
@property (nonatomic, retain) NSDate * date;
@property (nonatomic, readwrite) NSInteger *eventID;
@property (nonatomic, retain) CustomPlacemark * place;
@property (nonatomic, retain) NSMutableArray *invitedMembers;
@property (nonatomic, retain) NSMutableArray *acceptedMembers;


- (NSNumber*)getLatidude;
- (NSNumber*)getLongitude;

EventDTO.m

@synthesize place, date, eventID, name, acceptedMembers, description, invitedMembers;


- (NSNumber*)getLatidude{
    return [NSNumber numberWithDouble:place.coordinate.latitude];
}

- (NSNumber*)getLongitude{
    return [NSNumber numberWithDouble:place.coordinate.longitude];
}
4

4 に答える 4

0
LocateEventViewController *locView = [[LocateEventViewController alloc]init];
locView.eventDTO.name = eventName;
locView.eventDTO.date = eventDate;

を開始するときlocView、オブジェクト eventDTO は存在しません。そこで新しい eventDTO を開始する必要があります。

LocateEventViewController *locView = [[LocateEventViewController alloc]init];
YourClass *eventDTO = [[YourClass alloc] init];
locView.eventDTO = eventDTO;
locView.eventDTO.name = eventName;
locView.eventDTO.date = eventDate;

または追加し-initてあなたのメソッドに直接LocateEventViewController

-(id)init {
...
self.eventDTO = [[YourClassHere alloc] init];
...
}
于 2013-04-25T19:47:22.767 に答える