I want to see if a string, which is a title of a post on the apple rss news feed contains a substring, e.g. "Steve" or "Jobs". I organized the posts into a uitableview.
So there WAS a post which had Steve or Jobs in its title so I used this to check:
if ([[entry title] localizedCaseInsensitiveCompare:@"Steve"] == NSOrderedSame || [[entry title] localizedCaseInsensitiveCompare: @"Jobs"] == NSOrderedSame) {
NSLog(@"Comparism of Steve Jobs");
cell.imageView.image = [UIImage imageNamed:@"steve.png"];
}
But it was never called, entry is an RSSItem class which contains the title - the entry and its title is not my problem, I have checked. My comparism is the problem. How do i compare
UPDATE!
Ok here is the code:
NSRange range = [[[cell textLabel] text] rangeOfString:@"Steve" options:NSCaseInsensitiveSearch];
if (range.location != NSNotFound)
{
cell.imageView.image = [UIImage imageNamed:@"steve.png"];
}
I have tried it other peoples way also but SAME RESULT:
some cells have their imageView as steve.png even though their title doesnt contain steve jobs. Weird??? I scroll down and when I go back up all the dequeued cells which are reallocated and initialized have the steve jobs picture. At starting when i open the app some cells which don't have steve in their title DO HAVE THE IMAGE, and then the above happens.
My surrounding code IF NEEDED:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"UITableViewCell"]
autorelease];
}
tableView.autoresizingMask = 5;
tableView.autoresizesSubviews = YES;
cell.autoresizingMask = 5;
cell.frame = CGRectMake(cell.frame.origin.x, cell.frame.origin.y, 20, 20);
RSSItem *item = [[channel items] objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[item title]];
NSMutableString *string = [[NSMutableString alloc] initWithString:[[cell textLabel] text]];
if (string.length > 46) {
cell.textLabel.numberOfLines = 2;
UILineBreakMode lineBreak = UILineBreakModeClip;
cell.textLabel.lineBreakMode = lineBreak;
}
[string release];
tableView.backgroundColor = [UIColor darkGrayColor];
cell.textLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size: 12.0];
cell.backgroundColor = [UIColor whiteColor];
NSRange range = [[[cell textLabel] text] rangeOfString:@"Steve" options:NSCaseInsensitiveSearch];
if (range.location != NSNotFound)
{
cell.imageView.image = [UIImage imageNamed:@"steve.png"];
}
return cell;
}