------ 文章開始 ------

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIAlertViewDelegate,UITableViewDelegate,UITableViewDataSource>
{
    IBOutlet UITableView *tableView; 
    
    
    NSMutableArray *dataArray;
}


@property (strong, nonatomic) IBOutlet UITableView *tableView;
- (IBAction)blue:(id)sender;

@end
///////////////////////以上是.h黨/////////////////////////////////////////////////////////////////////////

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize tableView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    dataArray=[[NSMutableArray alloc] init];
    [dataArray addObject:@"num1"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return [dataArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SerchCell"];
    if(cell==nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SerchCell"];
        
    }
    cell.textLabel.text=[dataArray objectAtIndex:indexPath.row];
    cell.textLabel.numberOfLines = 1;
    [tableView setBackgroundColor:[UIColor clearColor]];
    [tableView setSeparatorColor:[UIColor darkGrayColor]];
    return cell;
}

- (IBAction)blue:(id)sender 
{
       [self.tableView beginUpdates];
       [dataArray addObject:@"num2"];
       int count=[dataArray count];
       NSIndexPath *indexPath=[NSIndexPath indexPathForRow:count-2 inSection:0];
       NSArray *array=[NSArray arrayWithObject:indexPath];
       [self.tableView insertRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationTop];
       [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
------ 文章結尾 ------

[複製網址] [開新視窗] [檢舉短網址] [QR條碼]

服務條款 - 加入會員(免費) - 回報問題網址 - 聯絡偶們 -

© 2025 PPT.cc