Ios don';t在UIScrollView中显示图像
我创建了2个类(Ios don';t在UIScrollView中显示图像,ios,objective-c,uiscrollview,Ios,Objective C,Uiscrollview,我创建了2个类(RecipeViewController&DetailViewController) RecipeView是向我显示4个单元格(书名)的TableViewController,DetailView是向我显示任何书籍的许多图像的UIViewController 我的问题是,当我点击任何单元格并转到下一页时,UIScroller不向我显示图像 这是我的代码: RecipeViewController.m - (void)tableView:(UITableView *)tableVi
RecipeViewController
&DetailViewController
)
RecipeView
是向我显示4个单元格(书名)的TableViewController
,DetailView
是向我显示任何书籍的许多图像的UIViewController
我的问题是,当我点击任何单元格并转到下一页时,UIScroller
不向我显示图像
这是我的代码:
RecipeViewController.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);
}
#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
DetailViewController.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);
}
#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
#导入“DetailViewController.h”
#导入“RecipeViewController.h”
@实现细节视图控制器
@综合滚动条,你的价值;
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
//m1变量在tableview中告诉我选择哪本书
int m1=[self.yourValue integerValue];
NSLog(@“m1:%d”,m1);
//此代码为我提供了图像数(书的页数)
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);
对于(int i=1;i嘿,您正在主线程中执行所有操作,可能会出现延迟或其他一些问题,通常不建议这样做,您是否可以使用NickLockWoods实现异步加载图像
这是一个非常好的UIImageView类别,您只需导入AsyncImageView即可使用该函数
[imageView setImageURL:@"ur url"];
它异步加载所有图像,并且有很多自定义项
就你而言:
for (int i = 1; i <= numbook; i++)
{
UIImageView *imagen = [[UIImageView alloc] initWithFrame: CGRectMake((i-1)*320, 0, 320, 460)];
[imagen setImageURL: [NSString stringWithFormat:@"192.168.1.102/mamal/book.php?p=%d&b=%d",i,m1]]];
[scroller addSubview:imagen];
}
for(int i=1;i如果您确实想使用[NSData DATA WITH CONTENTS OFURL:],请将其添加到循环、chnage url和图像视图框架中
for (int i = 1; i <= numbook; i++)
{
UIImageView *yourImage=[[UIImageView alloc]init];
yourImage.frame = CGRectMake((i-1)*320, 0, 320, 460);
[scroller addSubview:imagen];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.102/mamal/book.php?p=%d&b=%d",i,m1]];
NSData *imgData = [NSData dataWithContentsOfURL:url];
dispatch_sync(dispatch_get_main_queue(), ^{
UIImage *downloadedImage = [UIImage imageWithData:imgData];
yourImage.image = downloadedImage;
if(yourImage.image==nil)
{
[yourImage setImage:@"placeholder.png"];
}
});
});
}
for(int i=1;i这是什么NSInteger numbook=[numberbook integerValue];?仔细检查[UIImage imageWithData:dat]
是否为零?numbook的值是什么?numbook是整数变量,此方法:(NSInteger numbook=[numberbook integerValue];)将值从NSString保存到integermy friend我有很多url,我的问题是不要显示UIScroller查看很多图像我的朋友我有一个问题:我想更改url并在UIScroller图像中显示,以便我用于循环。上面的代码可以放在循环中吗?我的朋友我使用故事板,在其中放置两页UITableView和UIView,UIView在自己的完整页面中有UISCrollerView。是否有权使用UISCroll???