私は現在、ニュース アプリに取り組んでおり、ニュース記事の画像の表の行に画像を追加したいと考えています。
他のすべてを解析できましたが、画像の URL を解析できないだけです。
これは、フィードから HTML をストライピングするために使用したコードです。
.M ファイル
- (NSString *)stringByStrippingHTML:(NSString *)inputString
{
NSMutableString *outString;
if (inputString)
{
outString = [[NSMutableString alloc] initWithString:inputString];
if ([inputString length] > 0)
{
NSRange r;
while ((r = [outString rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
{
[outString deleteCharactersInRange:r];
}
}
}
return outString;
}
.H ファイル
- (NSString *)stringByStrippingHTML:(NSString *)inputString;
私は一般的にxcodeとコードにまったく慣れていないので、このことに慣れていません。
画像のURLを解析するだけではわかりません。
これは tablerow の外観のコードです。
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.numberOfLines=3;
cell.detailTextLabel.numberOfLines=4;
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *articleDateString = [dateFormatter stringFromDate:entry.articleDate];
NSString * articleDescrptionString = [[[NSString alloc] init] autorelease];
articleDescrptionString = entry.articleDescription;
cell.textLabel.text = entry.articleTitle;
NSString *plainString = [self stringByStrippingHTML:entry.articleDescription ];
cell.imageView.image = [UIImage imageNamed: entry.articleImageUrl];
//NSString *rangedString = [plainString substringToIndex:249]; //0 to 249 makes it 250 characters
//cell.detailTextLabel.text = articleDescrptionString;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@", articleDateString, plainString];
//UIImage *theImage = [UIImage imageWithContentsOfFile:entry.articleImageUrl];
//cell.imageView.image = theImage;
return cell;
}
私がコメントアウトしたコードは、現在使用されていないため、現在使用されていません。