2010-11-13 5 views
1

Я запускаю подробные страницы из UITableView, и на этой странице подробно отображается изображение. Я бы хотел, чтобы он был масштабируемым, поэтому я хотел бы, чтобы содержимое этой подробной страницы находилось в scrollView. Пока не удача, ярлыки, текстовые изображения и изображения в порядке, но я не могу заставить ScrollView реализован.Как реализовать UIScrollView программно

вот мой .m: СПАСИБО!

- (void)viewDidLoad { 

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
scrollView.contentSize = CGSizeMake(320, 700); 
scrollView.clipsToBounds = YES; 
super.view.backgroundColor = [UIColor whiteColor]; 
[scrollView setUserInteractionEnabled:YES]; 




self.navigationItem.title = [NSString stringWithFormat:selectedCellItem]; 



CGRect frame = CGRectMake(0, 0, 10, 10); 

self.view = [[UIView alloc] initWithFrame:frame]; 

self.view.backgroundColor = [UIColor whiteColor]; 



frame = CGRectMake(0, 320, 10, 10); 



UILabel *label = [[UILabel alloc] initWithFrame:frame]; 

//label.text = selectedCellItem; 


label.font=[UIFont fontWithName:@"Verdana-Bold" size:20.0]; 
label.textAlignment = UITextAlignmentCenter; 

[self.view addSubview:label]; 

[label release]; 

frame = CGRectMake(0, 320, 320, 60); //Description 



UITextView *labelDesc = [[UITextView alloc] initWithFrame:frame]; 

labelDesc.text = selectedCellDesc; 
labelDesc.font=[UIFont fontWithName:@"Verdana" size:12.0]; 
labelDesc.textAlignment = UITextAlignmentLeft; 

//labelDesc.textAlignment = UITextAlignmentTop; 

[self.view addSubview:labelDesc]; 

[labelDesc release]; 




frame = CGRectMake(0, 0, 320, 320); //Image 

UIImageView *imageItem = [[UIImageView alloc] initWithFrame:frame]; 
[imageItem setImage:[UIImage imageNamed:selectedCellImage]]; 

// GET THIS ONE WORKING RIGHT>>[imageItem setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@.png", [[NSBundle mainBundle] bundlePath], selectedCellImage]]]; //use 

//imageItem = [[UIImageView alloc] initWithContentsOfFile:[NSString stringWithFormat:@"shirt.png", [[NSBundle mainBundle] bundlePath]]]; 
//labelDesc.font=[UIFont fontWithName:@"Zapfino" size:13.0]; 
//labelDesc.textAlignment = UITextAlignmentCenter; 

imageItem.contentMode = UIViewContentModeScaleAspectFit; 
[self.view addSubview:imageItem]; 






//[imageItem release]; 

    [super viewDidLoad]; 

} 



/* 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
*/ 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 


@end 

ответ

0

Я думаю, что вам не хватает следующей строки, чтобы добавить UIScrollView в качестве подзаголовка.

[self.view addSubView: scrollView];

+0

Если я поместил эту строку кода в строку 5 (выше «self.navigationItem.title = [NSString stringWithFormat: selectedCellItem];»), это на самом деле приводит к сбою во время выполнения (хотя он компилируется отлично). Я очень ценю помощь tho ... любые другие идеи? – gabe

+0

Можете ли вы поделиться стеком вызовов для сбоя? –

+0

Счастливый поделиться одним. Спасибо большое! 2010-11-13 18: 02: 44.953 KeepMe [65124: 207] - [UIView addSubView:]: непризнанный селектор отправлен в экземпляр 0x7329b30 2010-11-13 18: 02: 44.956 KeepMe [65124: 207] *** Нагрузочного приложения из-за неперехваченное исключение 'NSInvalidArgumentException', причина: '- [UIView addSubView]: непризнанный селектор направил к экземпляру 0x7329b30' *** стек вызовов на первый броске: ( \t 0 CoreFoundation 0x025ed919 __exceptionPreprocess + 185 \t 1 libobjc.A.dylib 0x0273b5de – gabe

Смежные вопросы