I have a NSmutableArray like this.
[obj1,obj2,obj3,obj5,......];
this has assigned into a UITableView
lets say user clicked on the 3rd cell. then I need to create another NSMutableArray like this.
[obj3,obj4,obj5,------]; need to remove first few objects from the array upto the current object. How can I do this.
please help me.
Thanks
you can use this...for remove specific object from any mutable array...
[array removeObjectAtIndex:0];
Related
I have a problem. First I sended information from textfield with prepareForSegue. I sended from WelkomViewController to TableViewController. There I put the data in a NSMutableDictionary. It's a person and his values. Then I put the person in another NSMutableDictionary for multiple persons. In the tableview I create a list with only the full name of all the persons. And with a click on the row I want to give a new view with the details of the person that the client clicked on. But I can't send the data with prepareForSegue it seems.(see image)
What do I do wrong? Thx for every reply!
project
You're trying to use a dictionary like an array, which doesn't work (obviously). You should not count on a fixed order for [self.personen allKeys], it can change at any point during runtime, which would result in the wrong person being passed along.
You need to use a mutable array as your storage vessel for people names, then address them by the row of the index path.
First of all you need to use NSmutablearray to save data of people so make sure that self.personen is an NSmutablearray then you need just to use ObjectAtindex function to get the selected row .
vcGevensView.persoon=[self.personen objectAtIndex:indexPath.row];
I have to 2 NSArray and I merge it into NSMutableArray now I have to distinguish it. How many values in 1 NSArray and 2 also. My problem is that when I got 1 NSArray then I want to show red button before that in table view and 2 array i wnat to show green button. How can i achieve this. I want to show such type of result.
store all values in NSArray as dictionaries with 2 keys - one for the actual object and other for the array type(array1 or array2) and use the same to distinguish the objects in common array
it is better that for combining two array use
NSMutableDictionary rather than NSMutableArray
I have a NSMutableArray when it is added to, removed from, or changes the notifications from the array update my UITableView such that those changes are reflected in the UITableView automatically using KVO observing. This works great.
We now a have a new requirement that we want to filter out certain items from the array. This just shows what kind of filtering I would like to do:
NSIndexSet *indexes = [array indexesOfObjectsPassingTest:
^BOOL(MyObject *obj, NSUInteger idx, BOOL *stop)
{
return !obj.isHidden;
}];
NSMutableArray *newArray = [[array objectsAtIndexes:indexes] mutableCopy];
However, doing the above does not work, I can't create a new array because it is being monitored by the UITableView, and I want to preserve the fine grained notifications that we get from the insertions and removals from the model array rather than reloading the entire table when a change occurs. So what I need is a way to only get notifications from newly inserted or removed items from the model that also meet the criteria.
So what, I think, I really want is two arrays, one that is the model, and another is the filtered presentation array. The presentation array will register for KVO notifications with the model array. The UITableView will register for notifications on the filtered presentation array. So if the insertion occurs in the model array it will send notification to the presentation array, then I need to check if it meets the criteria before inserting it in the presentation array or if it does not, then ignore the insertion. The problem I having is getting this to work correctly, the order of the items in the model is important and must be preserved. Any help or suggestions for alternative approaches would be greatly appreciated.
you have to maintain the model array and combinate the notification with the new array. So for example:
#property (nonatomic, strong) NSArray *modelArray;
//This array is also initialized obviously
#property (nonatomic, strong) NSArray *filteredArray;
//On this array you put the array filtered and connect this with the notification.
//So you can start each time from the model array and set the filtered array (and so
//change automatically the tableView).
is it possible to declare an NSArray withobjects of view controllers?
I'm trying to use two buttons to call an array that will loop through and count through 20 different views.
Right now, my array works in calling and displaying multiple images in a single view application.
what would i do to create an nsarray of view controllers, so that every time the "next" action method is called, a new view is loaded, and essentially, counted through the array?
This is currently what I have listed in my array
-(IBAction)getNextView {
imageArray=[[NSArray arrayWithObjects:
[firstViewController.view],
[secondViewController.view],
[thirdViewController.view];
}
But I think i am missing a valid point of updating the mainview with the elements in the array...
Thanks!
UPDATE :
This is what I am trying to achieve...
yes why not, you can create an NSArray with objects of viewControllers
I have a UiSearchBar implemented in my TableView, and I also have two NSArrays, one for title and one for description. When I search through the array of the titles, it returns the right search, but when I click on a row that the search came with, I get "row 0" if I click on the first row. My question is how to make a connection between the two arrays so that when the search rearranges the titles based on the user search, the description array corresponds to the same row the title is at.
Simply do not use two NSArrays, but just one with custom NSObject objects:
#interface SomeObject : NSObject {
NSString *_title;
NSString *_description;
}
- (BOOL)matchesKeywords:(NSString *)keywords;
#end
Then you have all your information stored in one class, the way Obj-C is meant to be. You can easily perform the search because the objects itself sort of knows whether it matches a given keyword, so when you'd like to change SomeObject you can easily manage those changes in the class itself.
I did merge the two arrays into one, but that made the tableviewcell load alot slower because the cell is holding both, the title and description
I had this problem once So for the quick fix I did this:
In the header:
BOOL usingFilterArray;
Where you switch between the complete dictionary and the filtered one simply set the above BOOL to NO and YES respectively.
then in didSelectRowAtIndexPath use "if" statement to check the sate of the usingFilterArray.
Rest should be pretty easy. (Let me know if you still need help)
Just one thing when you perform the search after the filter Dictionary is hydrated if you cancel the search you need to make sure to run this or your app is going to crash as the hydrated dictionary will not have any object in it. (I assumed you cleaned the filtered Dictionary)
- (void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
[self.tableView reloadData];
}
Mate this is just a quick fix.