IOS登陆+注册+抽奖+排行榜

要求:三个页面(登录页面,pickerView页面,排行榜页面),pickerView页面是三个组件,每个组件显示0-9,点击按钮进行随机,获得的值存入排行榜,排行榜显示大于500的最高的10个分数和对应的用户名,切换页面可以用任何方法(0-9循环显示,登录注销[可以有不同的用户],判断用户名是否为邮箱[正则表达式])

 

说明:
1.要修改xml文件到当前系统桌面,dic.xml保存的是用户名和密码,array.xml是保存的积分榜
2.正则表达式用在注册页面,在注册用户的时候用户名需要经过正则表达式的验证,判断是否是邮箱
3.有一个默认的admin,admin账户
4.排行榜显示是用的tableView显示的


疑惑:
1.如何创建文件在当前项目下
2.为什么view之间传数组传不了,我知道数组要先初始化
3.数组排序,用内置的排序方法,compare:,从大到小用什么参数
4.如何让tableView中的table随array的改变而刷新

项目源码:http://download.csdn.net/detail/s10141303/5970243

步骤:

注册view

 


RegistViewController.h:

  1. #import <UIKit/UIKit.h>  
  2. @class LoginViewController;  
  3. @interface RegistViewController : UIViewController  
  4. - (IBAction)click:(id)sender;  
  5. @property (retain, nonatomic) IBOutlet UITextField *txtName;  
  6. @property (retain, nonatomic) IBOutlet UITextField *txtpassword;  
  7. @property (retain, nonatomic) IBOutlet UITextField *txtConfirmPassword;  
  8. @property(retain,nonatomic) NSMutableDictionary *dic;  
  9. @property(retain,nonatomic) LoginViewController *loginView;  
  10. @end  


RegistViewController.m:

  1. #import "RegistViewController.h"  
  2. #import "info.h"  
  3. #import "LoginViewController.h"  
  4. #define OK_BUTTON 0  //登陆按钮  
  5. #define CANCEL_BUTTON 1 //取消按钮  
  6. #define BOARD 2  //键盘点击  
  7. #define RETURN_BUTTON 3 //返回登陆界面  
  8. @interface RegistViewController ()  
  9.   
  10. @end  
  11.   
  12. @implementation RegistViewController  
  13.   
  14. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  
  15. {  
  16.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
  17.     if (self) {  
  18.           
  19.     }  
  20.     return self;  
  21. }  
  22.   
  23. - (void)viewDidLoad  
  24. {  
  25.     [super viewDidLoad];  
  26.     self.dic = [[[NSMutableDictionary alloc] init] autorelease];  
  27.     [self.dic setObject:@"admin" forKey:@"admin"];  
  28. }  
  29.   
  30. - (IBAction)click:(id)sender {  
  31.     UIButton *button = (UIButton*)sender;  
  32.     //登陆按钮  
  33.     if (button.tag == OK_BUTTON)  
  34.     {  
  35.         //[[info getInfo] initDic];//初始化dic,包含了admin账号  
  36.         NSString *path = @"Users/zl201/Desktop/dic.xml";  
  37.         NSMutableDictionary *dicc = [NSMutableDictionary dictionaryWithContentsOfFile:path];  
  38.         NSLog(@"文件读取成功");  
  39.         NSLog(@"%@",dicc);  
  40.         //如果为空  
  41.         if([self.txtName.text isEqualToString:@""]||[self.txtpassword.text isEqualToString:@""]||[self.txtConfirmPassword.text isEqualToString:@""])  
  42.         {  
  43.             UIAlertView * a = [[UIAlertView alloc] initWithTitle:@"友情提醒" message:@"输入不能为空" delegate:nil cancelButtonTitle:@"重试" otherButtonTitles:nil];  
  44.             [a show];  
  45.         }  
  46.         else  
  47.         {  
  48.             //检测注册是是否是邮箱  
  49.             if ([[info getInfo] isValidateEmail:self.txtName.text]) {  
  50.                   
  51.             [self.txtName resignFirstResponder];  
  52.             [self.txtpassword resignFirstResponder];  
  53.             [self.txtConfirmPassword resignFirstResponder];  
  54.             //看是否包含某个键  
  55.             if ([[dicc allKeys] containsObject:self.txtName.text]) {  
  56.                 UIAlertView * a = [[UIAlertView alloc] initWithTitle:@"友情提醒" message:@"该用户已经存在,请重新注册新用户名!" delegate:nil cancelButtonTitle:@"重试" otherButtonTitles:nil];  
  57.                 [a show];  
  58.                 self.txtName.text = @"";  
  59.                 self.txtpassword.text = @"";  
  60.                 self.txtConfirmPassword.text = @"";  
  61.             }  
  62.             else  
  63.             {  
  64.                 //查看是否两次密码不一样  
  65.                 if (![self.txtConfirmPassword.text isEqualToString:self.txtpassword.text]) {  
  66.                 UIAlertView * a = [[UIAlertView alloc] initWithTitle:@"友情提醒" message:@"两次输入密码不一样" delegate:nil cancelButtonTitle:@"重试" otherButtonTitles:nil];  
  67.                     [a show];  
  68.                     self.txtConfirmPassword.text = @"";  
  69.                 }  
  70.                 //注册成功  
  71.                 else{  
  72.                     UIAlertView * a = [[UIAlertView alloc] initWithTitle:@"" message:@"恭喜注册成功,请点击返回登陆界面按钮!" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:nil];  
  73.                     [a show];  
  74.                       
  75.                     [info getInfo].name = self.txtName.text;  
  76.                     [info getInfo].password = self.txtpassword.text;  
  77.                     NSLog(@"%@,%@",[info getInfo].name,[info getInfo].password);  
  78.   
  79.                     //写入文件  
  80.                     [self.dic setObject:self.txtpassword.text forKey:self.txtName.text];  
  81.                     NSLog(@"%@",self.dic);  
  82.                     NSString *path = @"Users/zl201/Desktop/dic.xml";  
  83.                     [self.dic writeToFile:path atomically:YES];  
  84.                     NSLog(@"文件写入成功");  
  85.                       
  86.                     self.txtConfirmPassword.text = @"";  
  87.                     self.txtpassword.text = @"";  
  88.                     self.txtName.text = @"";  
  89.                 }  
  90.             }  
  91.             }  
  92.             else  //不是邮箱  
  93.             {  
  94.                 UIAlertView *aa = [[UIAlertView alloc] initWithTitle:@"友情提醒" message:@"用户名必须是邮箱" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];  
  95.                 [aa show];  
  96.             }  
  97.         }  
  98.     }  
  99.     //取消按钮  
  100.     else if (button.tag == CANCEL_BUTTON)  
  101.     {  
  102.         self.txtName.text = @"";  
  103.         self.txtpassword.text = @"";  
  104.         self.txtConfirmPassword.text = @"";  
  105.         [self.txtName resignFirstResponder];  
  106.         [self.txtpassword resignFirstResponder];  
  107.         [self.txtConfirmPassword resignFirstResponder];  
  108.     }  
  109.     //面板触发退出键盘  
  110.     else if(button.tag == BOARD)  
  111.     {  
  112.         [self.txtName resignFirstResponder];  
  113.         [self.txtpassword resignFirstResponder];  
  114.         [self.txtConfirmPassword resignFirstResponder];  
  115.     }  
  116.     //返回登陆界面  
  117.     else if(button.tag == RETURN_BUTTON)  
  118.     {  
  119.         [self.loginView.view removeFromSuperview];  
  120.           
  121.         self.loginView = [[[LoginViewController alloc]initWithNibName:@"LoginViewController"bundle:nil]autorelease];  
  122.         [self.view insertSubview:self.loginView.view atIndex:10];  
  123.     }  
  124. }  
  125. - (void)dealloc {  
  126.     [_txtName release];  
  127.     [_txtpassword release];  
  128.     [_txtConfirmPassword release];  
  129.     [_dic release];  
  130.     [super dealloc];  
  131. }  
  132. @end  


登陆View


LoginViewController.h:

  1. #import <UIKit/UIKit.h>  
  2. @class RegistViewController;  
  3. @class SecondViewController;  
  4. @interface LoginViewController : UIViewController  
  5. @property (retain, nonatomic) IBOutlet UITextField *txtName;  
  6. @property (retain, nonatomic) IBOutlet UITextField *txtPassword;  
  7. @property (retain,nonatomic)RegistViewController *registView;  
  8. @property(retain,nonatomic)SecondViewController *secondView;  
  9. - (IBAction)click:(id)sender;  
  10. //接受保存当前登陆的账户和密码  
  11. @property(retain,nonatomic) NSString *name;  
  12. @property(retain,nonatomic) NSString *password;  
  13. @end  


LoginViewController.m:

  1. #import "LoginViewController.h"  
  2. #import "info.h"  
  3. #import "RegistViewController.h"  
  4. #import "SecondViewController.h"  
  5. #define OK_BUTTON 0  //登陆按钮  
  6. #define CANCEL_BUTTON 1 //退出系统  
  7. #define BOARD 2  //键盘点击  
  8. #define RESIGN_BUTTON 3 //注销按钮  
  9. #define REGISTER_BUTTON 4 //注册按钮  
  10. @interface LoginViewController ()  
  11.   
  12. @end  
  13.   
  14. @implementation LoginViewController  
  15.   
  16. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  
  17. {  
  18.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
  19.     if (self) {  
  20.         // Custom initialization  
  21.     }  
  22.     return self;  
  23. }  
  24.   
  25. - (void)viewDidLoad  
  26. {  
  27.     [super viewDidLoad];  
  28. }  
  29.   
  30. -(void)viewDidAppear:(BOOL)animated  
  31. {  
  32.     NSLog(@"%@",[info getInfo].name);  
  33.     NSLog(@"%@",[info getInfo].password);  
  34.         if ([info getInfo].name != NULL&&[info getInfo].password != NULL) {  
  35.             self.txtName.text = [info getInfo].name;  
  36.             self.txtPassword.text = [info getInfo].password;  
  37.         }  
  38. }  
  39.   
  40. - (void)dealloc {  
  41.     [_txtName release];  
  42.     [_txtPassword release];  
  43.     [_registView release];  
  44.     [_secondView release];  
  45.     [_name release];  
  46.     [_password release];  
  47.     [super dealloc];  
  48. }  
  49. - (IBAction)click:(id)sender {  
  50.     UIButton *button = (UIButton*)sender;  
  51.     //登陆按钮  
  52.     if (button.tag == OK_BUTTON)  
  53.     {  
  54.         [self.txtName resignFirstResponder];  
  55.         [self.txtPassword resignFirstResponder];  
  56.         //读取xml文件  
  57.         NSString *path = @"Users/zl201/Desktop/dic.xml";  
  58.         NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithContentsOfFile:path];  
  59.         NSLog(@"文件读取成功");  
  60.         NSLog(@"%@",dic);  
  61.         NSString *s =[dic objectForKey:self.txtName.text];  
  62.   
  63.         if ([s isEqualToString:self.txtPassword.text]) {  
  64.             [info getInfo].name = self.txtName.text;  
  65.             [info getInfo].password=self.txtPassword.text;  
  66.             UIAlertView * a = [[UIAlertView alloc] initWithTitle:@"登陆状态" message:@"恭喜登陆成功" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:nil];  
  67.             [a show];  
  68.               
  69.         }  
  70.         else  
  71.         {  
  72.             UIAlertView * a = [[UIAlertView alloc] initWithTitle:@"登陆状态" message:@"登陆失败" delegate:nil cancelButtonTitle:@"重试" otherButtonTitles:nil];  
  73.             [a show];  
  74.             self.txtName.text = @"";  
  75.             self.txtPassword.text = @"";  
  76.         }  
  77.     }  
  78.     //系统退出  
  79.     else if (button.tag == CANCEL_BUTTON)  
  80.     {  
  81.         exit(0);  
  82.     }  
  83.     //面板触发退出键盘  
  84.     else if(button.tag == BOARD)  
  85.     {  
  86.         [self.txtName resignFirstResponder];  
  87.         [self.txtPassword resignFirstResponder];  
  88.     }  
  89.     //注销按钮  
  90.     else if(button.tag == RESIGN_BUTTON)  
  91.     {  
  92.         [info getInfo].name=@"";  
  93.         [info getInfo].password=@"";  
  94.         self.txtName.text = @"";  
  95.         self.txtPassword.text = @"";  
  96.         [self.txtName resignFirstResponder];  
  97.         [self.txtPassword resignFirstResponder];  
  98.     }  
  99.     //注册按钮  
  100.     else if(button.tag == REGISTER_BUTTON)  
  101.     {  
  102.           
  103.         [self.registView.view removeFromSuperview];  
  104.           
  105.         self.registView = [[[RegistViewController alloc]initWithNibName:@"RegistViewController" bundle:nil]autorelease];  
  106.         [self.view insertSubview:self.registView.view atIndex:10];  
  107.           
  108.     }  
  109. }  
  110. @end  


抽奖view


ViewController.h:

  1. #import <UIKit/UIKit.h>  
  2. @class ShowViewController;  
  3. @interface SecondViewController : UIViewController<UIPickerViewDataSource,UIPickerViewDelegate>  
  4. @property (retain, nonatomic) IBOutlet UIPickerView *picker;  
  5. - (IBAction)click:(id)sender;  
  6. - (IBAction)OK:(id)sender;  
  7. @property(nonatomic,retain)NSArray *images;  
  8. @property(nonatomic,retain)NSArray *column1;  
  9. @property(nonatomic,retain)NSArray *column2;  
  10. @property(nonatomic,retain)NSArray *column3;  
  11. @property(nonatomic,retain)NSArray *column4;  
  12. @property(nonatomic,retain)NSArray *column5;  
  13. @property(nonatomic,assign)long num;  
  14. @property (retain, nonatomic) IBOutlet UILabel *lblShow;  
  15. @property(nonatomic,retain)ShowViewController *showView;  
  16. @property(nonatomic,retain)NSMutableArray *array;//记录分数  
  17. @end  


ViewController.m:

  1. #import "SecondViewController.h"  
  2. #import <AudioToolbox/AudioToolbox.h>  
  3. #import "info.h"  
  4. @interface SecondViewController ()  
  5.   
  6. @end  
  7.   
  8. @implementation SecondViewController  
  9.   
  10. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  
  11. {  
  12.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
  13.     if (self) {  
  14.         // Custom initialization  
  15.     }  
  16.     return self;  
  17. }  
  18.   
  19. - (void)viewDidLoad  
  20. {  
  21.     [super viewDidLoad];  
  22.     self.array = [[NSMutableArray alloc] init];  
  23.     UIImage *image1 = [UIImage imageNamed:@"apple.png"];  
  24.     UIImage *image2 = [UIImage imageNamed:@"bar.png"];  
  25.     UIImage *image3 = [UIImage imageNamed:@"cherry.png"];  
  26.     UIImage *image4 = [UIImage imageNamed:@"crown.png"];  
  27.     UIImage *image5 = [UIImage imageNamed:@"lemon.png"];  
  28.     UIImage *image6 = [UIImage imageNamed:@"seven.png"];  
  29.     self.images = @[image1,image2,image3,image4,image5,image6];  
  30.       
  31.     //创建30个ImageView  
  32.     for (int i=0; i<5; i++) {  
  33.         UIImageView *imageView1 = [[UIImageView alloc] initWithImage:image1];  
  34.         UIImageView *imageView2 = [[UIImageView alloc] initWithImage:image2];  
  35.         UIImageView *imageView3 = [[UIImageView alloc] initWithImage:image3];  
  36.         UIImageView *imageView4 = [[UIImageView alloc] initWithImage:image4];  
  37.         UIImageView *imageView5 = [[UIImageView alloc] initWithImage:image5];  
  38.         UIImageView *imageView6 = [[UIImageView alloc] initWithImage:image6];  
  39.         NSArray *arr = @[imageView1,imageView2,imageView3,imageView4,imageView5,imageView6];  
  40.         NSString *str = [NSString stringWithFormat:@"column%d",i+1];  
  41.         //OC特有方法,对一个可能存在可能不存在的变量赋值,本来是一个变量,可以转化成字符串,这样就可以改变字符串了  
  42.         [self setValue:arr forKey:str]; //KVC  
  43.         [imageView1 release];  
  44.         [imageView2 release];  
  45.         [imageView3 release];  
  46.         [imageView4 release];  
  47.         [imageView5 release];  
  48.         [imageView6 release];  
  49.     }  
  50.     srandom(time(NULL));  
  51.     //默认选择在第5000行  
  52.     for (int i=0; i<5; i++) {  
  53.         [self.picker selectRow:5000 inComponent:i animated:NO];  
  54.     }  
  55.       
  56. }  
  57.   
  58. -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView  
  59. {  
  60.     return 5;  
  61. }  
  62.   
  63. -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component  
  64. {  
  65.     return [self.images count]*10000;  
  66. }  
  67.   
  68. -(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view  
  69. {  
  70.     //这种写法非常消耗内存  
  71.     //    UIImageView *imageView = [[UIImage alloc] initWithImage:[self.images objectAtIndex:row]];  
  72.     //    return imageView;  
  73.     NSString * str = [NSString stringWithFormat:@"column%d",component+1];  
  74.     NSArray *arr = [self valueForKey:str];  
  75.     return [arr objectAtIndex:row%6];  
  76.       
  77. }  
  78.   
  79. - (void)dealloc {  
  80.     [_picker release];  
  81.     [_images release];  
  82.     [_column1 release];  
  83.     [_column2 release];  
  84.     [_column3 release];  
  85.     [_column4 release];  
  86.     [_column5 release];  
  87.     [_showView release];  
  88.     [_lblShow release];  
  89.     [super dealloc];  
  90. }  
  91. //退出  
  92. - (IBAction)click:(id)sender {  
  93.     //    NSLog(@"%@",srandom(time(nil)));  
  94.     exit(0);  
  95. }  
  96. //确定  
  97. - (IBAction)OK:(id)sender {  
  98.     int a[5];  
  99.     bool f=false;  
  100.     for (int i=0; i<5; i++) {  
  101.         int row = random() % [self.column1 count];  
  102.         int n = random() % 35;  
  103.         int j = row *n;  
  104.         [self.picker selectRow:j inComponent:i animated:YES];  
  105.         a[i]=j%6;  
  106.     }  
  107.     int sum=0;  
  108.     for (int i=0; i<5; i++)  
  109.     {  
  110.         sum = 1;  
  111.         if (f==false)  
  112.         {  
  113.             for (int j=i+1; j<5; j++)  
  114.             {  
  115.                 if (a[i] == a[j])  
  116.                 {  
  117.                     sum++;  
  118.                 }  
  119.                 if (sum>=3)  
  120.                 {  
  121.                     f=true;  
  122.                     break;  
  123.                 }  
  124.             }  
  125.         }  
  126.         else  
  127.         {  
  128.             break;  
  129.         }  
  130.     }  
  131.     if (f) {  
  132. //        UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"我中了" message:@"中了500万" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil];  
  133. //        [a show];  
  134.         //[self playMusic:@"win"];//调用播放音乐  
  135.     }  
  136.     [self playMusic:@"crunch"];  
  137.     self.num = a[0]*10000+a[1]*1000+a[2]*100+a[3]*10+a[4];  
  138.     [info getInfo].number = self.num;  
  139.     NSLog(@"%d",self.num);  
  140.     NSLog(@"%@",[info getInfo].name);  
  141.       
  142.       
  143.     //self.lblScore.text = [NSString stringWithFormat:"当前得分:%d",self.num];  
  144.     self.lblShow.text = @"";  
  145.     NSLog(@"%@",[info getInfo].name);  
  146.     if ([info getInfo].name!=NULL&&self.num>=4000) {  
  147.   
  148.         NSString *str = [NSString stringWithFormat:@"恭喜%@获得%d的高分上榜了",[info getInfo].name,self.num];  
  149.         self.lblShow.text = str;  
  150.         CGSize size = [self.lblShow.text sizeWithFont:self.lblShow.font];  
  151.         CGRect frame = CGRectMake(self.lblShow.frame.origin.x, self.lblShow.frame.origin.y, size.width, self.lblShow.frame.size.height);  
  152.         self.lblShow.frame = frame;  
  153.         NSLog(@"恭喜获得4000以上的高分");  
  154.         [self.array addObject:[NSString stringWithFormat:@"%@                %d",[info getInfo].name,self.num]];  
  155.         NSLog(@"%@",self.array);  
  156.         NSString *path = @"Users/zl201/Desktop/array.xml";  
  157.         [self.array writeToFile:path atomically:YES];  
  158.         NSLog(@"文件写入成功");  
  159.     }  
  160.     else if ([info getInfo].name!=NULL&&self.num<4000)  
  161.     {  
  162.         NSString *str = [NSString stringWithFormat:@"%@,很遗憾只有%d分,不足4000,加油",[info getInfo].name,self.num];  
  163.         self.lblShow.text = str;  
  164.         CGSize size = [self.lblShow.text sizeWithFont:self.lblShow.font];  
  165.         CGRect frame = CGRectMake(self.lblShow.frame.origin.x, self.lblShow.frame.origin.y, size.width, self.lblShow.frame.size.height);  
  166.         self.lblShow.frame = frame;  
  167.     }  
  168. }  
  169.   
  170. -(void)playMusic:(NSString*)s  
  171. {  
  172.     //通过NSBundle来获得音频文件的url地址  
  173.     NSURL *url = [[NSBundle mainBundle] URLForResource:s withExtension:@"wav"];  
  174.     SystemSoundID winSound;//整形类型的id  
  175.     //用音频服务,为音频文件绑定soundID  
  176.     AudioServicesCreateSystemSoundID((CFURLRef)url, &winSound);  
  177.     //通过绑定的soundId来播放音乐  
  178.     AudioServicesPlayAlertSound(winSound);  
  179. }@end  


排行榜View


ShowViewController.h:

  1. #import <UIKit/UIKit.h>  
  2. @class SecondViewController;  
  3. @interface ShowViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>  
  4. @property (retain, nonatomic) IBOutlet UITableView *tableView;  
  5. @property(nonatomic,retain)NSMutableArray *array;//加上头行显示给tableView  
  6. @property(nonatomic,retain)NSMutableArray *array1;//记录分数  
  7. @property(nonatomic,retain)SecondViewController *secView;  
  8. @end  


ShowViewController.m:

    1. #import "ShowViewController.h"  
    2. #import "SecondViewController.h"  
    3. @interface ShowViewController ()  
    4.   
    5. @end  
    6.   
    7. @implementation ShowViewController  
    8.   
    9. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  
    10. {  
    11.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
    12.     if (self) {  
    13.         // Custom initialization  
    14.     }  
    15.     return self;  
    16. }  
    17.   
    18. - (void)viewDidLoad  
    19. {  
    20.     [super viewDidLoad];  
    21.     NSString *path = @"Users/zl201/Desktop/array.xml";  
    22.     self.array1 = [NSArray arrayWithContentsOfFile:path];  
    23.     NSLog(@"文件读入成功");  
    24.     NSLog(@"%@",self.array1);  
    25.     [self.array1 sortUsingSelector:@selector(compare:options:)];   //如何倒序  
    26.     NSLog(@"%@",self.array1);  
    27.     self.array = [NSMutableArray arrayWithObject:@"积分排行榜(>=4000):"];  
    28.     [self.array addObjectsFromArray:self.array1];  
    29.       
    30. }  
    31.   
    32. - (void)didReceiveMemoryWarning  
    33. {  
    34.     [super didReceiveMemoryWarning];  
    35.     // Dispose of any resources that can be recreated.  
    36. }  
    37.   
    38. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView  
    39. {  
    40.     return 1;  
    41. }  
    42.   
    43. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  
    44. {  
    45.     return [self.array count];  
    46. }  
    47.   
    48. - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
    49. {  
    50.     NSString *MyIdentifier = @"MyIdentifier";  
    51.       
    52.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];  
    53.     if (cell == nil) {  
    54.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];  
    55.     }  
    56.     NSString  *titleStr = [self.array objectAtIndex:indexPath.row];  
    57.       
    58.     cell.textLabel.text = titleStr;  
    59.     return cell;  
    60. }  
    61.   
    62. -(void)dealloc  
    63. {  
    64.     [_array release];  
    65.     [_tableView release];  
    66.     [super dealloc];  
    67. }  
    68.   
    69. @end  
感谢来访,共同学习!
原文地址:https://www.cnblogs.com/dingxiaowei/p/3267132.html