我在实施分段控制时遇到了麻烦。我相信我已经把所有东西都搞定了,但是当我点击分段控件的任何一边时,这个方法都没有被调用。
标头文件
#import <UIKit/UIKit.h>
#import "ServiceConnector.h"
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMessageComposeViewController.h>
#import <AddressBook/AddressBook.h>
#import "Global.h"
@interface ContactInfo : NSObject
@property char group;
@property (nonatomic, retain) NSString* firstName;
@property (nonatomic, retain) NSString* lastName;
@property (nonatomic, retain) NSString* phoneNumber;
@property int isSelected;
@end
@interface Friends : UIViewController<UITableViewDataSource, UITableViewDelegate, ServiceConnectorDelegate, MFMessageComposeViewControllerDelegate>{
UISegmentedControl *segmentedControl;
}
@property (nonatomic, retain) IBOutlet UITableView* tblFriends;
@property (nonatomic, retain) IBOutlet UIButton* btnAdd;
@property (nonatomic, retain) IBOutlet UIButton* btnInvite;
@property (nonatomic, retain) IBOutlet UIButton* btnDone;
@property (nonatomic, retain) NSMutableArray* contactList;
@property (nonatomic, retain) NSMutableArray* contactGroup;
@property (nonatomic, retain) NSMutableArray* friendList;
@property (nonatomic, retain) NSString* modeStr;
@property (nonatomic,retain) IBOutlet UISegmentedControl *segmentedControl;
- (IBAction) InviteClicked;
- (IBAction) AddClicked;
- (IBAction) DoneClicked;
- (IBAction)segmentSwitch;
- (void) sendSMS:(NSString*) phoneNumber;
- (void) sendInviteSMS:(NSMutableArray*) resipients;
- (void) getContacts;
- (void) groupFromContacts;
- (void) groupFromFriends;
// table delegates
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
// service connector delegate
- (void)requestReturnedData:(NSData*)data;
//message delegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result;
@end
简化版的实施(方法已被删除)
#import "Friends.h"
#import "JSONKit.h"
@interface Friends ()
@end
@implementation ContactInfo
@end
@implementation Friends
@synthesize segmentedControl;
- (void)viewDidLoad
{
_friendList = [[NSMutableArray alloc] init];
_contactList = [[NSMutableArray alloc] init];
[self AddClicked];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void) dealloc
{
[segmentedControl release];
[_friendList release];
[_contactList release];
[super dealloc];
}
- (IBAction)segmentSwitch {
switch (self.segmentedControl.selectedSegmentIndex) {
case 0:
[self AddClicked];
break;
case 1:
[self InviteClicked];
break;
default:
break;
}
}
@end
这是分段控制的连接检查器
答案 0 :(得分:5)
您需要将控件挂钩到“Value Changed”事件,而不是“Touch Up Inside”事件。