奇怪的行为UIActionSheet + UITableView:行消失
我有一个UITableView与其中的一些静态单元格。其中一人触摸时显示UIActionSheet。代码如下:奇怪的行为UIActionSheet + UITableView:行消失
viewDidLoad:初始化控件。
- (void)viewDidLoad
{
[super viewDidLoad];
[self initializeControls];
}
initializeControls:将手势识别器添加到单元格内的标签以显示UIActionSheet。
- (void)initializeControls {
[...]
// Places Label
self.placeNamesLabel.userInteractionEnabled = YES;
tapGesture = \
[[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(didPlaceNamesLabelWithGesture:)];
[self.placeNamesLabel addGestureRecognizer:tapGesture];
tapGesture = nil;
[...]
}
didPlaceNamesLabelWithGesture:初始化UIActionSheet,加故事板一个UITableView和关闭按钮。
- (void)didPlaceNamesLabelWithGesture:(UITapGestureRecognizer *)tapGesture
{
// Show UITableView in UIActionView for selecting Place objects.
placesActionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[placesActionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect tableFrame = CGRectMake(0, 40, 0, 0);
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
AddArticlesPlacesViewController *placesView = [storyBoard instantiateViewControllerWithIdentifier:@"PlacesForArticle"];
placesView.managedObjectContext = self.managedObjectContext;
placesView.view.frame = tableFrame;
[placesActionSheet addSubview:placesView.view];
placesView = nil;
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissPlacesActionSheet:) forControlEvents:UIControlEventValueChanged];
[placesActionSheet addSubview:closeButton];
closeButton = nil;
[placesActionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[placesActionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}
dismissPlacesActionSheet:关闭UIActionSheet。
-(void)dismissPlacesActionSheet:(id)sender {
[placesActionSheet dismissWithClickedButtonIndex:0 animated:YES]; }
一切正常,UITableView从核心数据填充罚款。那么问题在哪里?重点是,当任何行被挖掘,整个表变空(我不能张贴图像,对不起)。
我试着用一个按钮添加一个新的自定义行,将按钮继续添加到AddArticlesPlacesViewController;这工作正常,行为如预期。所以问题出在UIActionSheet和UITableView之间。
下面是两个视图控制器的接口:
主。
@interface AddArticleViewController : UITableViewController <NSFetchedResultsControllerDelegate, [...]>
[...]
@property (weak, nonatomic) IBOutlet UILabel *placeNamesLabel;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
[...]
@end
中学。
@interface AddArticlesPlacesViewController : UITableViewController <NSFetchedResultsControllerDelegate>
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@end
我被卡住了。我究竟做错了什么?
问候。
佩德罗文图拉。
可以使用的tableview的委托方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
NSLog(@"indexpath-->%d",indexPath.row);
if (indexPath.row==0 || indexPath.row == 2)
{
NSLog(@"row %d",indexPath.row);
}
if (indexPath.row==1)
{
actionsheet=[[UIActionSheet alloc]initWithTitle:@"Sample" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:nil, nil];
[actionsheet showInView:self.view];
}
}
你也可以使用UIActionsheetDelegate的方法选择按钮:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"index==>%d",buttonIndex);
NSLog(@"cancel");
}
我做到了,在UIActionSheet中没有触发此事件。 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@“Selected row%@”,indexPath); } – Pedro
使用UIActionSheet时,不会调用shouldHighlightRowAtIndexPath,didSelectRowAtIndexPath和didSelectRowAtIndexPath;但是这些其他的:numberOfSectionsInTableView,sectionIndexTitlesForTableView,numberOfRowsInSection,cellForRowAtIndexPath。 – Pedro
是不是因为placesView管理对象上下文和placesView =零? –
@verbumdei:我认为它不是,UITableView在两个解决方案(UIActionSheet内部和外部)中显示来自Core Data的数据。 – Pedro