1
我有一些問題。我想在scrollview中顯示靜態和動態對象。我有IBOutlets,他們已連接。我想更改消息和標題,它們是在代碼中手動創建的。所有其他對象都是靜態的。我的代碼是在這裏:uiscrollview中的靜態和動態對象
.h文件中:
@interface MessageContentViewController(){
IBOutlet UIImageView *avatarImageView;
IBOutlet UIScrollView *scrollView;
IBOutlet UIImageView *msgBoardImg;
IBOutlet UIImageView *topBarImg;
IBOutlet UIButton *backBtn;
NSMutableArray *allMessages;
}
@property int indexOfMsg;
@end
.m文件:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]]];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[scrollView setContentSize:CGSizeMake(scrollView.frame.size.width * allMessages.count, 0)];
[scrollView setPagingEnabled:YES];
[scrollView scrollRectToVisible:CGRectMake(scrollView.frame.size.width * indexOfMsg, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height) animated:NO];
for (int i = 0; i < allMessages.count; i++) {
UIView *tempSubView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * i, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
[tempSubView addSubview:topBarImg];
[tempSubView addSubview:backBtn];
[tempSubView addSubview:msgBoardImg];
[tempSubView addSubview:avatarImageView];
[scrollView addSubview:tempSubView];
}
[scrollView setContentOffset: CGPointMake(scrollView.frame.size.width * indexOfMsg, 0)];
CGRect currentViewFrame = CGRectMake(scrollView.frame.size.width * indexOfMsg, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height);
[scrollView scrollRectToVisible:currentViewFrame animated:NO];
}
的.xib文件:
請幫助我。提前致謝。
我很驚訝。 scrollview沒有顯示。 – 2013-03-01 05:25:46
我用額外的視圖控制器(.xib)解決了這個問題。 – 2013-03-01 10:30:47