hi i am new to iPhone.what i did is creating an array with images as shown below
images = [NSMutableArray alloc] initWithObjets:#"image1.jpg",#"image2.jpg",#"image3.jpg",#"image4.jpg",#"image5.jpg",#"image6.jpg",nil]
and i create a button when ever button click images are exchanged for that i am writing code as fallows in button clicked event.
[_images exchangeObjectAtIndex:2 withObjectAtIndex:4];
but images are not exchanged and i did n't get any warnings and images.i am writing array in viewDidLoad.what is the wrong.how can i exchange elements in the array. thank u in advance.
Are you getting an array of images to then put into a UIImage so it goes through all the images one by one?
If so then when you change this array it will not change the order of the UIImages. You will need to change the array as you currently are then assign the array to the UIImage again like you would have done before. This would then show you the new and hopefully correct sequence of images.
I may be a bit wrong and you are using each location in the array to create a UIImage then put all those UIImages into a UIImageView. But what i am saying still applies, you would have to assign the new array to the UIImageView.
Related
I'll try to explain my self, I have ContactsViewController that shows a table view with a list of contacts (the model is an array of Contact objects), each cell display an image of a contact.
Currently what I do to populate the cell's UIImageView is this:
1. I override the Contact image property getter -
- (UIImage *)contactImage
{
if (!_contactImage) {
_contactImage = [[UIImage imageNamed:#"placeHolder.png"] retain];
[self asyncDownloadContactImageFromServer];
}
return _contactImage;
}
Then when I finish downloading the image I set it to the contactImage property and I post a ContactUpdatedImageNotification.
My ContactsViewController then get this notification and reload the cell of this contact, this will set the downloaded image to the cell's imageView.
The result of this is good async fetching of the images without blocking the UI while the user scroll the table view.
BUT there is something small that bothers me, when the a user scroll the table view and reveal new cells the new cell's image get download as expected but the cell's imageView is not updated with the new downloaded image till the user pick up his finger.
I supposed that I need to do something in another thread to make this effect, but I don't know how?
The image is not updated until the user stops scrolling due the code being executed in the default runloop, which gets delayed until scrolling finishes. This other question deals with the difference between the runloops, NSDefaultRunLoopMode vs NSRunLoopCommonModes and it precisely recommends not updating the images while scrolling since that can introduce jerkiness in the scrolling itself if you are not careful.
Also, now that you know about the existence of these runloop modes you will be able to find much more information about them in the xcode documentation or internet.
Hey Eyal visit following url...you will get answer and as well sample code...
tableview with different cell with different images
Hope this will help you...
In my application i parsed some JSON RSS feed and stored the parsed data into a NSMutableArray.
here ,i want to display only 4 items in my tableview at a time . Below the tableview , there a UIButton 'more'. When the user clicks this button, i want to display another 4 like that ..... How to do that.
Can any one give me an idea or point me any simple example that i can refer . How can i do some pagination with the parsed data . Thanks in advance .......
http://www.iphonedevsdk.com/forum/iphone-sdk-development/6676-paging-tableview.html
As you already know there is a data source for a uiTableView. You can easily achieve this as your requirement needs a button press. Pagination without button press on scroll of the table view would be tricky.
You have to create a NSMutableArray as a data source. Everytime the more button is pressed add 4 items to the end of the NSMutableArray.
Using NSRange you can get the objects from the main array and add them 4 at a time to the data source. Once you add call [tableview reload];
Also you can create the data source again
NSArray *dataSource = [mainArray subarrayWithRange:NSMakeRange(0, PageNum*4)];
Usually When i want a object to be accesed by many different event calls i just declare it in the h file.
However im making a app where i need to allow the user to create UILabels and drag and drop them where they want. So i have the code to make the labels and a alertview where they change the text.
-(IBAction)AddText{
UITextField *TextView;
TextView = [[UITextView alloc] initWithFrame:CGRectMake(40.0, 40.0, 40, 40)];
[self.view addSubview:TextView];
Which works however i need the user to be able to create many textviews which each have a unique name and a way i can reference them later such as TextView.text, doing it this way always creates a object named TextView and i can only reference it from his event, otherwise its undeclared.
Im really stuck at how i would go about doing this if anyone could help it would be great!,
Thanks
You could think about adding the newly created label to a NSMutableArray or, better, to a NSMutableDictionary. This latter solution gives you the possibility of creating a dictionary in which each label can be referred to using a string key. If you put such a dictionary in your .h file you'll be fine, I think.
How about creating an NSMutableArray of NSDictionary items. The dictionary items could have a reference to the label as well as things like name, and other relevant meta information.
You can add the UITextViews to a collection of some sort, depending on how you want to retrieve them later.
Hey all, here's the deal...
I've got a UIImage that is being loaded in the background via an NSURLConnection within a subclassed UIImageView. Until the data finishes downloading, a placeholder image is shown. The UIImage needs to be used by another, separate UIImageView, as well.
The problem I'm having is that if I set the second UIImageView's image property to that of the subclassed object before the download is complete, the second UIImageView never displays the downloaded image, since it's image prop is pointing to the placeholder.
Is there anyway to pass a pointer to a pointer between these two UIImageViews?
I've tried things like this:
imageView2.image = &[imageView1 image];
imageView2.image = *[imageView1 image];
But these don't seem to work. Any ideas?
Those pointers look particularly gross. The problem with doing it that way is that, even though you might be updating the data pointed to by those pointers, you are not notifying your UIImageView subclasses that the data has changed, and thus they don't know to redraw.
Instead of playing with that pointer mess, why not use Key-Value Observing instead? If you have a separate thread running that downloads the UIImage, you can just tell your UIImageViews to observe that property and when your downloader class is finished downloading all the data and has put it into the property, the views will get a notification and can then display the image.
Can't you just catch the connectionDidFinishLoading: message from the NSURLConnection and then set the second image?
I have created a subclass of UIImageView and I am handling the touches for its objects inside the subclass itself.
Now when the user is about to exit the app I want to save the state of the images. And as there are multiple transforms which might have taken place on the images (I am saving all the transforms in a dictionary), I want to be able to save these objects in applicationWillTerminate.
I am using the encodeWithCoder and initWithCoder methods. The objects are saved and loaded as expected (at least looks like it). But when I print the frame size and origin, I get some absurd values on the console.
Can someone please tell me if the frame is not saved when encodeWithCoder is called and the contents are stored in a file?
Thanks.
Why don't you serialize the UIImageView's frame along with the actual UIImageView? Just add another property in encodeWithCoder and initWithCoder for the frame. This way, you can be sure to have the correct frame if you feel something is off.
Please paste the code where you are logging the values of the UIImageView's frame. I believe you may be casting to the wrong type which will cause your values to be off.
write Dictionary content to plist by using NSUserDefault's object for key , and setobject for key method