在我的 iPhone 应用程序中,我有ViewController1
一个UILabel
被调用的应用程序selectedBook
,我在情节提要中添加了它的视图并连接了插座。
我有另一个视图控制器,我从toViewController2
传递一些数据,其中的文本就是其中之一。ViewController2
ViewController1
UILabel
在ViewController1
我写了以下代码:
在 ViewController1.h
@interface ViewController1 : UIViewController{
IBOutlet UILabel *selectedBook;
NSString *BookName;
NSString *BookCover;
NSString *BookAbout;
}
@property (nonatomic, retain) NSString *BookName;
@property (nonatomic, retain) NSString *BookCover;
@property (nonatomic, retain) NSString *BookAbout;
-(void) setTheSelectedBook:(NSString *)bookName bookCover:(NSString *)bookCover bookAbout:(NSString *)bookAbout userID:(int)userID;
在 ViewController1.m
-(void) setTheSelectedBook:(NSString *)bookName bookCover:(NSString *)bookCover bookAbout:(NSString *)bookAbout userID:(int)userID
{
BookName = bookName;
BookCover = bookCover;
BookAbout = bookAbout;
NSLog(@"in setTheSelectedBook, BookName: %@ - BookCover: %@ - BookAbout: %@ - userID: %d", BookName, BookCover, BookAbout, userID);
selectedBook.text = bookName;
}
在viewController2
我写了以下代码:
ViewController1 *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Suggest"];
[viewController setTheSelectedBook:@"MybookName" bookCover:@"MyBookCover" bookAbout:@"MuBookAbout" userID:1];
我的数据正确传递,我在输出中看到它,但问题是UILabel
文本没有更新,这意味着这一行
selectedBook.text = bookName;
不起作用。
我试着把它写成这样selectedBook.text = @"someText";
,这很有效。
我无法理解selectedBook.text = bookName;
工作缺少什么?我希望有人在这个问题上帮助我。
提前致谢。