スクロールすると「あああ」の位置がおかしくなってしまいます。
原因がわかりません・・・。
写真を添付させて頂きます。
お分かりになる方はいらっしゃいませんでしょうか?
又、myDataSourceの容量より1枠多めに表示しております。
これはindex.pathが0の時だけ別データを表示する為です。
------------------------------------------------------
ViewController1.m
------------------------------------------------------
#import "ViewController1.h"
#import "MyTableViewCell.h"
@implementation ViewController1
@synthesize url;
#pragma mark -
#pragma mark View lifecycle
/*
// UICOLOR http://iphone-tora.sakura.ne.jp/uicolor.html
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0 || indexPath.row%2 == 0) {
UIColor *color = [UIColor colorWithRed:1.0 green:0.98 blue:0.667 alpha:0.7];
cell.backgroundColor = color;
}
}
*/
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
// タイトル
// self.title = @"RSS取得";
parser = [[RSSParser alloc] init];
[parser parseRSSData:[NSURL URLWithString:url]];
// NSLog( @"%@", rssURL);
myDataSource = [[NSMutableArray alloc] init];
// myDataSource = [parser items];
[myDataSource addObjectsFromArray:[parser items]];
// [myDataSource addObjectsFromArray:[parser items]];
}
#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [myDataSource count]+1;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
MyTableViewCell *cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if( indexPath.row == 0 ){
cell.textLabel.text = @"あああ";
}else{
[cell setLabelText:[myDataSource objectAtIndex:indexPath.row-1]];
}
return cell;
}
#pragma mark -
#pragma mark Table view delegate
// セルが選択されたら
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
if( indexPath.row != 0 ){
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.item = [myDataSource objectAtIndex:indexPath.row-1];
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
}
*/
NSLog( @"%d", indexPath.row );
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
------------------------------------------------------
MyTableViewCell.m
------------------------------------------------------
#import "MyTableViewCell.h"
@implementation MyTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.contentView.frame.size.height*0.5, self.contentView.frame.size.width, self.contentView.frame.size.height*0.5)];
titleLabel.font = [UIFont systemFontOfSize:12];
titleLabel.backgroundColor = [UIColor clearColor];
pubDateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, self.contentView.frame.size.width-20, self.contentView.frame.size.height*0.4)];
pubDateLabel.font = [UIFont systemFontOfSize:12];
pubDateLabel.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:titleLabel];
[self.contentView addSubview:pubDateLabel];
// self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// [self.imageView setImage:[UIImage imageNamed:@"back.png"]];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)setLabelText:(Item *)item {
titleLabel.text = item.title;
pubDateLabel.text = item.pubDate;
}
- (void)dealloc {
[titleLabel release];
[pubDateLabel release];
[super dealloc];
}
@end