`
xhanxhanxhan
  • 浏览: 203289 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

QQ - iPhone 风格的好友列表实现

QQ 
阅读更多
//
//  QQstyleTableViewViewController.h
//  QQstyleTableView
//
//  Created by xhan on 9/22/09.
//  Copyright In-Blue 2009. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface QQstyleTableViewViewController : UIViewController < UITableViewDelegate , UITableViewDataSource , UIScrollViewDelegate > {
	UITableView* _tableView;
	NSMutableArray* _array;
	BOOL *flag;
}

@property (nonatomic, retain) UITableView *tableView;

- (int)numberOfRowsInSection:(NSInteger)section;

@end


 
//
//  QQstyleTableViewViewController.m
//  QQstyleTableView
//
//  Created by xhan on 9/22/09.
//  Copyright In-Blue 2009. All rights reserved.
//

#import "QQstyleTableViewViewController.h"

@implementation QQstyleTableViewViewController

@synthesize tableView = _tableView;

////////////////////////////////////////////////////////////////////////////////////////
// NSObject 
- (void)dealloc {
	free(flag);
    [_tableView release], _tableView = nil;
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
	_tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds  style:UITableViewStylePlain];
	_tableView.delegate = self;
	_tableView.dataSource = self;

	[self.view addSubview:_tableView];
	_array = [[NSMutableArray alloc] initWithObjects:[[NSArray alloc] initWithObjects:@"AA",@"BB",@"CC",@"DD",nil],
													 [[NSArray alloc] initWithObjects:@"EE",@"FF",@"GG",@"XX",@"ZZ",nil],	
													 [[NSArray alloc] initWithObjects:@"JJ",@"VV",@"EE",@"NN",nil],
													 nil];
	flag = (BOOL*)malloc([_array count]*sizeof(BOOL*));
	memset(flag, NO, sizeof(flag));

}

////////////////////////////////////////////////////////////////////////////////////////
// 
#pragma mark Table view  delegate methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [_array count];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return [self numberOfRowsInSection:section];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	static NSString *CellIdentifier = @"CellIdentifier";
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
	NSString* str = [[_array objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
	cell.textLabel.text = str;
	return cell;
}



- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
	UIButton *abtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//	abtn.frame = CGRectMake(0, 0, 200, 48);
//	abtn.titleLabel.text = @"HEADER";
	abtn.tag = section;
	[abtn addTarget:self action:@selector(headerClicked:) forControlEvents:UIControlEventTouchUpInside];
	return abtn;
}

////////////////////////////////////////////////////////////////////////////////////////
// 
-(void)headerClicked:(id)sender
{
	int sectionIndex = ((UIButton*)sender).tag;
	flag[sectionIndex] = !flag[sectionIndex];
	[_tableView reloadData];
}

- (int)numberOfRowsInSection:(NSInteger)section
{
	if (flag[section]) {
		return [(NSArray*)[_array objectAtIndex:section] count];
	}
	else {
		return 0;
	}
}

@end

分享到:
评论
5 楼 cbc009 2009-09-26  
没图没真相
4 楼 哇你长得真高 2009-09-24  
介个。。。
截图出来应该是这样的:一个tableview的列表,每行一个名字,与球球无关。。。
标题党
3 楼 showtime520 2009-09-24  
无图五真相啊,期待
2 楼 tuti 2009-09-23  
是啊,这兄弟当大家都是IPHONE啊,能直接运行程序啊。给个截图啊
1 楼 lordhong 2009-09-23  
呵呵, 哥们来个截图看下?

相关推荐

Global site tag (gtag.js) - Google Analytics