我创建了 2 个类(RecipeViewController
& DetailViewController
)
,RecipeView
它TableViewController
向我展示了 4 个单元格(书名),它DetailView
可以向我展示任何一本书的许多图像。UIViewController
UIScroll
我的问题是当我单击任何单元格并转到下一页时UIScroller
不向我显示图像。
这是我的代码:
食谱视图控制器.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int x = (indexPath.row)+1;
NSLog(@"x : %d",x);
DetailViewController *obj = [[DetailViewController alloc]init];
obj.yourValue = [NSString stringWithFormat:@"%d",(indexPath.row)+1];
[self presentModalViewController:obj animated:YES];
NSLog(@"yourValue1 : %@",obj.yourValue);
}
细节视图控制器.m
#import "DetailViewController.h"
#import "RecipeViewController.h"
@implementation DetailViewController
@synthesize scroller,yourValue;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//m1 variable tell me in tableview which choice book
int m1 = [self.yourValue integerValue];
NSLog(@"m1 : %d",m1);
//this code give me number of images (pages of book)
NSString *numberbook = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.102/mamal/book.php?info=0&b=%d",m1]]];
NSInteger numbook = [numberbook integerValue];
NSLog(@"%d",numbook);
for (int i = 1; i <= numbook; i++)
{
//this code for recive images from specific book
NSData *dat = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.102/mamal/book.php?p=%d&b=%d",i,m1]]];
NSLog(@"%@",dat);
UIImageView *imagen = [[UIImageView alloc] initWithImage:[UIImage imageWithData:dat]];
imagen.frame = CGRectMake((i-1)*320, 0, 320, 460);
[scroller addSubview:imagen];
}
scroller.delegate = self;
scroller.contentSize = CGSizeMake(320*numbook, 460);
scroller.pagingEnabled = YES;
}
@end
对不起我的英语不好!!!