Implementation requirements for the most recent browsing features:
There is such a requirement in the project, and the user pushed into the homepage to go to the next page to browse the information, and then to the "my" page has a recently browsed feature, showing the most recently browsed data, up to 3. Ideas:
1, in the Browse details page record ID array, stored in the Nsuserdefault;
1.1, first take out the data in the Nsuserdefault to determine whether it is empty;
1.2, empty, then the description of the previous data, then initialize the array, add data, save;
1.3, is not empty, then the data before the description, to determine whether the word browsing ID in the array;
If in, then delete the duplicate element first, if not, do not do operation;
1.4, to determine whether the array count is greater than or equal to 3;
If greater than or equal to 3, then delete the first element, if not, do not do the operation;
2, in my page, take out the array from the Nsuserdefault, request the network, get the data display; question:
When I store an array of IDs, the first store is correct, but the second time, the page crashed, I really do not understand AH. Error Tip:
'-[__nscfarray Insertobject:atindex:]: Mutating method sent to immutable object ' Error reason:
means to change the method sent to a constant object (do not understand). To modify the method:
Then declare a variable array of 2 and manipulate the variable array 2 data .... Modified code:
#pragma mark-Recent browse-(void) Nearlylookcarwithmodel: (Detailchoosecarmodel *) Detailmodel {//remove array Nsmutablearray *ar
Ray = [[Nsmutablearray alloc] init];
Array = [[Nsuserdefaults standarduserdefaults] objectforkey:mylookcar];
if (array) {NSLog (@ "not nil");
The presence of this array nsmutablearray *marr = [[Nsmutablearray alloc] initwitharray:array];
NSLog (@ "Last marr:%@", MARR);
Saved into a dictionary, including CID, phono, title nsdictionary *cardic = [nsdictionary dictionarywithobjectsandkeys:self.cid,@ "CID", detailmodel.main_photo,@ "Imgname", detailmodel.car_subject,@ "Ti
Tle ", nil];
if ([MArr containsobject:cardic]) {NSLog (@ "contains duplicate elements");
Delete duplicate elements [mArr removeobject:cardic];
} if ([MArr Count] >= 3) {NSLog (@ ">3");
Deletes the first element [MARR removeobjectatindex:0];
} [MArr Addobject:cardic]; NSLog (@ "This marr:%@", MARR);
Operation Array [[Nsuserdefaults standarduserdefaults] Setobject:marr Forkey:mylookcar];
}else {NSLog (@ "nil");
Initialize MARR nsmutablearray *marr = [[Nsmutablearray alloc] init];
Saved into a dictionary, including CID, phono, title nsdictionary *cardic = [nsdictionary dictionarywithobjectsandkeys:self.cid,@ "CID", detailmodel.main_photo,@ "Imgname", detailmodel.car_subject,@ "Ti
Tle ", nil];
[MArr Addobject:cardic];
[[Nsuserdefaults Standarduserdefaults] Setobject:marr Forkey:mylookcar];
}
}