Iphone 在UITableView中展开行
我有一个带有六行的Iphone 在UITableView中展开行,iphone,uitableview,row,Iphone,Uitableview,Row,我有一个带有六行的UITableView。每行的左边都有一个“+”号。单击该按钮,将显示详细信息。例如,数据的描述 再次单击时,细节将消失。我如何实现这一点 请帮帮我 提前感谢。如果您只能为iOS5构建应用程序,请查看WWDC 2011 Session 125视频 UITableView更改、提示和技巧 它解释了如何做到这一点。如果你必须支持旧版本,它至少会给你一个想法 //下面是我为FAQ编写的代码 //here is a code i made for FAQ //hope it ans
UITableView
。每行的左边都有一个“+”号。单击该按钮,将显示详细信息。例如,数据的描述
再次单击时,细节将消失。我如何实现这一点
请帮帮我
提前感谢。如果您只能为iOS5构建应用程序,请查看WWDC 2011 Session 125视频 UITableView更改、提示和技巧 它解释了如何做到这一点。如果你必须支持旧版本,它至少会给你一个想法
//下面是我为FAQ编写的代码
//here is a code i made for FAQ
//hope it answers your question
//if you want to test it, you just need to hook up your table view to _faqTableView
#import "ViewController.h"
@interface ViewController ()
{
NSArray *questions;
NSArray *answers;
NSMutableArray *datasource;
NSIndexPath *insertedLocation;
NSIndexPath *answerIndexPath;
}
-(void)deleteFrom:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath;
-(void)insertInto:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_faqTableView.dataSource = self;
_faqTableView.delegate = self;
questions = [NSArray arrayWithObjects:@"What", @"is", @"your", @"name", nil];
answers = [NSArray arrayWithObjects:@"kdjfl", @"kdlfjs", @"kdljfel", @"kjldfkjsle", nil];
datasource = [NSMutableArray arrayWithArray:questions];
insertedLocation = [NSIndexPath indexPathForRow:[datasource count] inSection:0];
answerIndexPath = insertedLocation;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [datasource count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"FAQ Cell Identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
if (indexPath.row != answerIndexPath.row) {
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
} else {
cell.textLabel.numberOfLines = 0;
}
cell.textLabel.text = [datasource objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row != insertedLocation.row) {
[tableView beginUpdates];
if (indexPath.row == insertedLocation.row -1 &&
insertedLocation.row!= [datasource count]) {
[self deleteFrom:tableView atIndexPath:[NSIndexPath indexPathForRow:indexPath.row +1 inSection:0]];
insertedLocation = [NSIndexPath indexPathForRow:[datasource count] inSection:0];
} else {
NSInteger i = indexPath.row;
if (insertedLocation.row != [datasource count]) {
[self deleteFrom:tableView atIndexPath:insertedLocation];
if (insertedLocation.row < i) {
i --;
}
}
insertedLocation = [NSIndexPath indexPathForRow:i + 1 inSection:0];
[self insertInto:tableView atIndexPath:insertedLocation];
}
[tableView endUpdates];
NSLog(@"inserted row %d", insertedLocation.row);
}
}
-(void)deleteFrom:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath
{
[datasource removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
-(void)insertInto:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath
{
[datasource insertObject:[answers objectAtIndex:indexPath.row - 1] atIndex:indexPath.row];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
answerIndexPath = indexPath;
}
@end
//希望它能回答你的问题
//如果要测试它,只需将表视图连接到_faqTableView即可
#导入“ViewController.h”
@界面视图控制器()
{
NSArray*问题;
NSArray*答案;
NSMutableArray*数据源;
NSIndexPath*插入位置;
nsindepath*answerindepath;
}
-(void)deleteFrom:(UITableView*)tableView atIndexPath:(NSIndexPath*)indexPath;
-(void)insertInto:(UITableView*)tableView atIndexPath:(nsindepath*)indepath;
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
_faqTableView.dataSource=self;
_faqTableView.delegate=self;
问题=[NSArray arrayWithObjects:@“什么”,“是”,“你的”,“名字”,无];
answers=[NSArray数组,其对象为:@“kdjfl”@“kdlfjs”@“kdljfel”@“kjldfkjsle”,nil];
datasource=[NSMutableArrayWithArray:questions];
insertedLocation=[NSIndexPath indexPathForRow:[datasource count]子节:0];
answerindexath=插入位置;
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
返回[数据源计数];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*cellIdentifier=@“常见问题解答单元格标识符”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
如果(!单元格){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:cellIdentifier];
}
if(indexPath.row!=answerIndexPath.row){
cell.accessoryType=UITableViewCellAccessoryDetailDisclosure按钮;
}否则{
cell.textlab.numberOfLines=0;
}
cell.textlab.text=[datasource objectAtIndex:indexath.row];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
返回单元;
}
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
if(indexPath.row!=insertedLocation.row){
[tableView开始更新];
if(indexath.row==insertedLocation.row-1&&
insertedLocation.row!=[数据源计数]){
[self-deleteFrom:tableView-atIndexPath:[NSIndexPath-indexPathForRow:indexPath.row+1节:0];
insertedLocation=[NSIndexPath indexPathForRow:[datasource count]子节:0];
}否则{
NSInteger i=indexPath.row;
if(insertedLocation.row!=[数据源计数]){
[自删除源:tableView路径:insertedLocation];
if(insertedLocation.row
请参见