English 中文(简体)
基于用户投入的图像
原标题:iOS load an image based on user input

对目标C和SOS发展(来自PHP)来说,是一个比较简单的问题,我似乎无法找到答案:

我也看到了一个分裂的例子。 浏览设计,如果一个用户在主意中点击某一项目时将网页装入《详细观点》。 我全力以赴,但愿以网络观点取代形象。 因此,我修改了装上UIImage的电灯,而不是装上网上电文。 我所期望的是,这相当于这一法典:

NSString *urlString = [pagesAddress objectAtIndex:indexPath.row];
NSURL *url = [NSURL URLWithString:urlString];

// these 2 is where I get lost with the images.
NSURLRequest = *request = [NSURLRequest requestWithURL:url];
[detailViewController.webView loadRequest:request];

我来到这里:

NSString *imageName = [pagesAddress objectAtIndex:indexPath.row];
UIImage *myImage = [UIImage imageNamed:imageName];

// missing the last 2 calls: one to tell Xcode that it s an image "request" I want and the second to load the actual image (based on it s name that is already in an array) into the ImageView.

感谢。

PS

我试图这样做:

NSString *imageName = [pagesAddress objectAtIndex:indexPath .row];
[detailViewController.imageView setImage:[UIImage imageNamed:imageName]]; 

这只是第一个形象,然后在我试图显示最后一个形象时坠毁。

最佳回答

最后,在我修改法典时,解决办法是这两行:

NSString *imageName = [pagesAddress objectAtIndex:indexPath.row];
[detailViewController.imageView setImage:[UIImage imageNamed:imageName]];

通知说,我不得不改变把国家安全局改成统一分类或X代码的定点。 飞机倒塌的原因是,在我有图像名称的阵列中,我把3个图像放入一个条目(主要是我忘了 com!)这样,它就已经消失了。

时间:

你给我的信

UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];

is unnecessary because I already have a view created, it would create another view which I never used. Also, replacing it with CGRect seems overkill if I already have a UIImage placeholder no?

无论如何,它现在运作,我非常感谢所有帮助。 带有目标C的iPad发育是一条非常棘手的道路,我期望我会把更多的东西.在你们身上。

乘客。

问题回答

为此:

UIImage *myImage = [[UIImage alloc] initWithData:[NSData dataWithConentsOfURL:[NSURL URLWithString:urlString];
// don t know if you already got the following?
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
[imageView setImage:myImage];
[self.view addSubview:imageView];

第1行是同步的(=阻塞),因此,在生产过程中,你应当为此使用<代码>-[NSURLRequeststart](但这一条更为复杂)。


或利用这些图像拍摄当地形象:

UIImage *myImage = [UIImage imageNamed:imageName];
// Now, follow the same steps as in the first code-example, just skip the first line.

引申(关于4.0和之后):

// Execute a block of code on a background thread.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
               ^(void) 
{
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    UIImage* image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
    // When IO is done and image created, set it on the main thread.
    dispatch_async(dispatch_get_main_queue(), 
                   ^(void) 
    {
        imageView.image = image;
    });
    [pool release];
});




相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签