Has anyone noticed with the changes added to UISwitch in Beta 4, that if you set a switches tag, for some reason it doesn't respect it? I add a switch programmatically to the accessory view of a TableView cell and once the cell is selected I access the switch to get it's tag to know which switch it was and the state that was changed.
Here are the code examples:
if (_showSwitch) {
if (cell.accessoryView == nil) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
switchview = [[UISwitch alloc]initWithFrame:CGRectZero];
switchview.tag = indexPath.row;
cell.accessoryView = switchview;
[switchview addTarget:self action:#selector(switchChanged:)
forControlEvents:UIControlEventValueChanged];
cell.backgroundColor = UIColor.systemGray2Color;
}
NSArray *strArray = [_tableDataSource[indexPath.row] componentsSeparatedByString:#"/"];
_row = indexPath.row;
_cellLabel = strArray[0];
cell.textLabel.text = _cellLabel;
_cellArray = [_cellArray arrayByAddingObject:(NSString *)_cellLabel];
if (_level >= 1) {
_deviceID = strArray[1];
_deviceArray = [_deviceArray arrayByAddingObject:_deviceID];
_lowcaseDeviceID = _deviceID = _deviceID.lowercaseString;
dictLookup = _statusDict[_lowcaseDeviceID];
if (_row >= 1) {
mycmdString = [mycmdString stringByAppendingString:#","];
}
mycmdString = [mycmdString stringByAppendingString:_deviceID];
UISwitch *switchView = (UISwitch *)cell.accessoryView;
[switchView setOn:NO animated:NO];
if ([dictLookup isEqualToString:#"ON"]) {
cell.textLabel.textColor = UIColor.systemGreenColor;
[switchView setOn:YES animated:YES];
}
_callForStatus = TRUE;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
- (IBAction)ControlView:(UISwitch *)sender {
ControlViewController *flController = [[ControlViewController alloc]
initWithNibName:#"ControlViewController" bundle:nil];
(flController.navigationItem).title = [NSString stringWithFormat:#"%# - %#", _deviceName, _device];
_level = _level += 1;
flController.deviceID = _device;
flController.deviceName = _deviceName;
flController.deviceState = #"OFF";
if ((sender.isOn) == YES) {
flController.deviceState = #"ON";
}
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
[self presentViewController:flController animated:YES completion:nil];
});
}
- (void)switchChanged:(UISwitch *)sender {
bool mode;
UISwitch *switchControl = sender;
if (switchControl.isOn == YES) {
[switchControl setOn:YES animated:YES];
mode = TRUE;
[General playSound:#"Button Up.mp3"];
} else {
[switchControl setOn:NO animated:NO];
mode = FALSE;
[General playSound:#"Button Down.mp3"];
}
sender.highlighted = YES;
_callForStatus = TRUE;
[self executeSwitchAtRow:switchControl.tag forMode:mode];
// if (_level >= 1) [self startStepperTimer];
}
- (void)executeSwitchAtRow:(NSInteger)row forMode:(BOOL)onoff {
NSString *mode = #"OFF";
if (onoff) {
mode = #"ON";
}
NSString *device = _deviceArray[row];
Debug_1(#"Send Switch Change for device %# %#",device,mode);
NSString *execCommand = [NSString stringWithFormat:#"device %# %#", mode, device];
[[NSNotificationCenter defaultCenter] postNotificationName:#"sendMessageFromExternal" object:self
userInfo:#{ #"cmd": execCommand }];
if (_level >= 1) [self startStepperTimer];
}
...
Related
I have tableviews in my storyboard and it is working till Xcode 7.3, After Updating Xcode to 8, imageviews that are added in tableviewcell are not render first time until you scroll OR explicitly call reloadData. Imageviews are added from storyboard.
After scrolling
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ALContactCell *contactCell;
switch (indexPath.section)
{
case 0:
{
//Cell for group button....
contactCell = (ALContactCell *)[tableView dequeueReusableCellWithIdentifier:#"groupCell"];
//Add group button.....
UIButton *newBtn = (UIButton*)[contactCell viewWithTag:101];
[newBtn addTarget:self action:#selector(createGroup:) forControlEvents:UIControlEventTouchUpInside];
newBtn.userInteractionEnabled = YES;
}break;
case 1:
{
//Add rest of messageList
contactCell = (ALContactCell *)[tableView dequeueReusableCellWithIdentifier:#"ContactCell"];
[contactCell.mUserNameLabel setFont:[UIFont fontWithName:[ALApplozicSettings getFontFace] size:USER_NAME_LABEL_SIZE]];
[contactCell.mMessageLabel setFont:[UIFont fontWithName:[ALApplozicSettings getFontFace] size:MESSAGE_LABEL_SIZE]];
[contactCell.mTimeLabel setFont:[UIFont fontWithName:[ALApplozicSettings getFontFace] size:TIME_LABEL_SIZE]];
[contactCell.imageNameLabel setFont:[UIFont fontWithName:[ALApplozicSettings getFontFace] size:IMAGE_NAME_LABEL_SIZE]];
contactCell.unreadCountLabel.backgroundColor = [ALApplozicSettings getUnreadCountLabelBGColor];
contactCell.unreadCountLabel.layer.cornerRadius = contactCell.unreadCountLabel.frame.size.width/2;
contactCell.unreadCountLabel.layer.masksToBounds = YES;
//contactCell.mUserImageView.hidden = NO;
contactCell.mUserImageView.layer.cornerRadius = contactCell.mUserImageView.frame.size.width/2;
contactCell.mUserImageView.layer.masksToBounds = YES;
[contactCell.onlineImageMarker setBackgroundColor:[UIColor clearColor]];
UILabel* nameIcon = (UILabel*)[contactCell viewWithTag:102];
nameIcon.textColor = [UIColor whiteColor];
ALMessage *message = (ALMessage *)self.mContactsMessageListArray[indexPath.row];
ALContactDBService *contactDBService = [[ALContactDBService alloc] init];
ALContact *alContact = [contactDBService loadContactByKey:#"userId" value: message.to];
ALChannelDBService * channelDBService =[[ALChannelDBService alloc] init];
ALChannel * alChannel = [channelDBService loadChannelByKey:message.groupId];
if([message.groupId intValue])
{
ALChannelService *channelService = [[ALChannelService alloc] init];
[channelService getChannelInformation:message.groupId orClientChannelKey:nil withCompletion:^(ALChannel *alChannel)
{
contactCell.mUserNameLabel.text = [alChannel name];
contactCell.onlineImageMarker.hidden=YES;
}];
}
else
{
contactCell.mUserNameLabel.text = [alContact getDisplayName];
}
contactCell.mMessageLabel.text = message.message;
contactCell.mMessageLabel.hidden = NO;
if ([message.type integerValue] == [FORWARD_STATUS integerValue])
contactCell.mLastMessageStatusImageView.image = [ALUtilityClass getImageFromFramworkBundle:#"mobicom_social_forward.png"];
else if ([message.type integerValue] == [REPLIED_STATUS integerValue])
contactCell.mLastMessageStatusImageView.image = [ALUtilityClass getImageFromFramworkBundle:#"mobicom_social_reply.png"];
BOOL isToday = [ALUtilityClass isToday:[NSDate dateWithTimeIntervalSince1970:[message.createdAtTime doubleValue]/1000]];
contactCell.mTimeLabel.text = [message getCreatedAtTime:isToday];
[self displayAttachmentMediaType:message andContactCell:contactCell];
// here for msg dashboard profile pic
[nameIcon setText:[ALColorUtility getAlphabetForProfileImage:[alContact getDisplayName]]];
if([message getGroupId])
{
[contactCell.onlineImageMarker setHidden:YES];
}
else if(alContact.connected && [ALApplozicSettings getVisibilityForOnlineIndicator])
{
[contactCell.onlineImageMarker setHidden:NO];
}
else
{
[contactCell.onlineImageMarker setHidden:YES];
}
if(alContact.block || alContact.blockBy)
{
[contactCell.onlineImageMarker setHidden:YES];
}
BOOL zeroContactCount = (alContact.unreadCount.intValue == 0 ? true:false);
BOOL zeroChannelCount = (alChannel.unreadCount.intValue == 0 ? true:false);
if(zeroChannelCount || zeroContactCount)
{
contactCell.unreadCountLabel.text = #"";
[contactCell.unreadCountLabel setHidden:YES];
}
if(!zeroContactCount && [alContact userId] && (message.groupId.intValue == 0 || message.groupId == NULL)){
[contactCell.unreadCountLabel setHidden:NO];
contactCell.unreadCountLabel.text=[NSString stringWithFormat:#"%i",alContact.unreadCount.intValue];
}
else if(!zeroChannelCount && [message.groupId intValue]){
[contactCell.unreadCountLabel setHidden:NO];
contactCell.unreadCountLabel.text = [NSString stringWithFormat:#"%i",alChannel.unreadCount.intValue];
}
contactCell.mUserImageView.backgroundColor = [UIColor whiteColor];
if([message.groupId intValue])
{
[contactCell.mUserImageView setImage:[ALUtilityClass getImageFromFramworkBundle:#"applozic_group_icon.png"]];
NSURL * imageUrl = [NSURL URLWithString:alChannel.channelImageURL];
if(imageUrl)
{
[contactCell.mUserImageView sd_setImageWithURL:imageUrl];
}
nameIcon.hidden = YES;
}
else if(alContact.contactImageUrl)
{
NSURL * theUrl1 = [NSURL URLWithString:alContact.contactImageUrl];
[contactCell.mUserImageView sd_setImageWithURL:theUrl1];
nameIcon.hidden = YES;
}
else
{
nameIcon.hidden = NO;
[contactCell.mUserImageView sd_setImageWithURL:[NSURL URLWithString:#""]];
contactCell.mUserImageView.backgroundColor = [ALColorUtility getColorForAlphabet:[alContact getDisplayName]];
}
}break;
default:
break;
}
return contactCell;
}
After long hit and trials it worked after updating
dispatch_async(dispatch_get_main_queue(), ^{
contactCell.mUserImageView.layer.cornerRadius = contactCell.mUserImageView.frame.size.width/2;
contactCell.mUserImageView.layer.masksToBounds = YES;
});
OR
you can use context graphics to get circular image
But still need a prior solution
I've been brought in on this project where the previous developers made custom table cells and headers by using xib files and then registering the nibs like so:
[self.accountTable registerNib:[UINib nibWithNibName:kNonATITableViewCellLandscapeNib bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kNonATITableViewCellLandscapeIdentifier];
[self.accountTable registerNib:[UINib nibWithNibName:kNonATITableHeaderLandscapeNib bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kNonATITableHeaderLandscapeId];
The header files have buttons in them and uiimageviews. The buttons are for sorting, the uiimageviews for an arrow icon to show you the direction of the sort (asc, desc). All the buttons and imageviews are IBOutlets. All the buttons are linked to an IBAction:
- (IBAction)sortButtonTouched:(id)sender;
The file also has two other properties:
#property (nonatomic, assign) SortType currentSortingOption;
#property (nonatomic, strong) UIButton* btnLastTouched;
Here is sortButtonTouched:
- (IBAction)sortButtonTouched: (UIButton*) buttonTouched {
if (!self.btnLastTouched) {
self.btnLastTouched = buttonTouched;
}
NSString* strFieldToSort;
UIImageView* ivSortImage;
NSArray* arrSortIcons = [[NSArray alloc] initWithObjects:self.ivAccountSort,self.ivNameSort, self.ivAddressSort, self.ivCitySort, self.ivZipSort, self.ivLastCallSort, self.ivMileageSort, nil];
//get the image for the button selected
if (buttonTouched.tag == 0) {
strFieldToSort = #"customerNumber";
ivSortImage = self.ivAccountSort;
} else if (buttonTouched.tag == 1) {
strFieldToSort = #"customerName";
ivSortImage = self.ivNameSort;
} else if (buttonTouched.tag == 2) {
strFieldToSort = #"address";
ivSortImage = self.ivAddressSort;
} else if (buttonTouched.tag == 3) {
strFieldToSort = #"city";
ivSortImage = self.ivCitySort;
} else if (buttonTouched.tag == 4) {
strFieldToSort = #"zip";
ivSortImage = self.ivZipSort;
} else if (buttonTouched.tag == 5) {
strFieldToSort = #"lastCallDate";
ivSortImage = self.ivLastCallSort;
} else if (buttonTouched.tag == 6) {
strFieldToSort = #"mileage";
ivSortImage = self.ivMileageSort;
}
//set the sort option and add icon
if (!self.currentSortingOption) {
self.currentSortingOption = SORT_ASC;
[ivSortImage setImage:[UIImage imageNamed:Ascending_Icon]];
} else {
if (![self.btnLastTouched isEqual:buttonTouched]) {
self.currentSortingOption = SORT_ASC;
[ivSortImage setImage:[UIImage imageNamed:Ascending_Icon]];
} else {
if (self.currentSortingOption == SORT_ASC) {
self.currentSortingOption = SORT_DESC;
[ivSortImage setImage:[UIImage imageNamed:Descending_Icon]];
} else {
self.currentSortingOption = SORT_ASC;
[ivSortImage setImage:[UIImage imageNamed:Ascending_Icon]];
}
}
}
//show and hide
for(int i=0; i<arrSortIcons.count; i++) {
UIImageView* ivThisImage = [arrSortIcons objectAtIndex:i];
if (buttonTouched.tag == i) {
[UIView animateWithDuration:.25 animations:^(void) {
ivThisImage.alpha = 1.0;
}];
} else {
[UIView animateWithDuration:.25 animations:^(void) {
ivThisImage.alpha = 0.0;
}];
}
}
//call back to routing view controller and sort results based on sort order and field selected
NSDictionary* dictUserData = [[NSDictionary alloc] initWithObjectsAndKeys:
#"Sort Non-ATI", #"Action",
strFieldToSort, #"Field To Sort",
[NSNumber numberWithLong:self.currentSortingOption], #"Sortng Option",
nil];
[[NSNotificationCenter defaultCenter] postNotificationName:#"rvc" object:self userInfo:dictUserData];
self.btnLastTouched = buttonTouched;
}
And the notification fires this method:
- (void) sortNonATIResults : (NSDictionary*) dictSortParams {
if (self.arrNonATIResults.count > 0) {
NSString* sortKey = [dictSortParams objectForKey:#"Field To Sort"];
//change the field to sort to match the customerInfo object properties...
NSNumber* numSortType = [dictSortParams objectForKey:#"Sortng Option"];
BOOL isAsc = YES;
if ([numSortType intValue] == 2) {
isAsc = NO;
}
NSSortDescriptor* sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortKey ascending:isAsc];
NSArray* arrSortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
NSArray* arrSortedNonATIResults = (NSArray*)[self.arrNonATIResults sortedArrayUsingDescriptors:arrSortDescriptors];
self.arrNonATIResults = [arrSortedNonATIResults mutableCopy];
self.arrDatasource = self.arrNonATIResults;
[self.accountTable reloadData];
}
}
There are two problems right now. The icons are not showing up if the notification is sent. Comment out the notification and they function as expected. The other problem is that the property currentSortingOption doesn't retain it's value. I think both issues are related but I am not 100% sure. When the tableview is reloaded, does the header get instantiated again? This would make sense to me since then the uiimageviews would be reset with no image and the property would lose it's value and reset to 0 (it is the value of a typedef).
So, I am correct, how can I resolve this and if not, what could be causing the problems?
Thanks
OK, sorry for posting and then solving my problem right away, I guess sometimes you just need to write out the problem to find the solution. All I needed to do was not reload the table but just reload the rows. Here's the updated method:
(void) sortNonATIResults : (NSDictionary*) dictSortParams {
if (self.arrNonATIResults.count > 0) {
NSString* sortKey = [dictSortParams objectForKey:#"Field To Sort"];
//change the field to sort to match the customerInfo object properties...
NSNumber* numSortType = [dictSortParams objectForKey:#"Sortng Option"];
BOOL isAsc = YES;
if ([numSortType intValue] == 2) {
isAsc = NO;
}
NSSortDescriptor* sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortKey ascending:isAsc];
NSArray* arrSortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
NSArray* arrSortedNonATIResults = (NSArray*)[self.arrNonATIResults sortedArrayUsingDescriptors:arrSortDescriptors];
self.arrNonATIResults = [arrSortedNonATIResults mutableCopy];
self.arrDatasource = self.arrNonATIResults;
dispatch_async(dispatch_get_main_queue(), ^{
NSMutableArray *indexPathArray = [[NSMutableArray alloc] init];
for (NSInteger section = 0; section < [self.accountTable numberOfSections]; ++section)
{
for (NSInteger row = 0; row < [self.accountTable numberOfRowsInSection:section]; ++row)
{
[indexPathArray addObject:[NSIndexPath indexPathForRow:row inSection:section]];
}
}
[self.accountTable reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationNone];
[self.accountTable scrollsToTop];
});
}
}
A button in a tablecell is visible, when a check is true and not visible, when the check is false.
Here are the part of the function:
BOOL checked = [self checkObjekt:object];
if (checked == YES ) {
[cell.buttonUpload setHidden:NO];
[cell.buttonUpload setTitle:#"Geprüft, Upload!" forState:UIControlStateNormal];
[cell.buttonUpload setEnabled:YES];
} else {
[cell.buttonUpload setHidden:YES];
[cell.buttonUpload setTitle:#"Ungeprüft" forState:UIControlStateNormal];
[cell.buttonUpload setEnabled:NO];
}
I have proofed if the data from the object are correct. And in all databases are the value are true or yes, so the button should be visible. With the same database-file are only on some devices are the button not visible.
All Devices are on iOS 8.1.3 and they are iPad mini Retina.
Here is the full function:
- (void)configureCell:(MbsStartCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
Objekt *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSDate *rawDate = [object valueForKey:#"termin"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"dd.MM.yyyy"];
NSString *strLabelUhrzeitbis;
if (nil != object.uhrzeitbis && ![object.uhrzeitbis isEqualToString:#""])
{
strLabelUhrzeitbis = object.uhrzeitbis;
cell.labelDatum.text = [NSString stringWithFormat:#"%# zwischen %# und %#", [dateFormatter stringFromDate:rawDate], object.uhrzeit, strLabelUhrzeitbis];
}
else
{
cell.labelDatum.text = [NSString stringWithFormat:#"%# um %#", [dateFormatter stringFromDate:rawDate], object.uhrzeit];
}
NSSet *adressen = object.adressen;
NSArray *adressenArray = [adressen allObjects];
for (Adresse *adresse in adressenArray)
{
if ([adresse.typ isEqualToString:#"Baustelle"])
{
if (adresse.anschrift1 && ![adresse.anschrift1 isEqualToString:#""])
{
cell.labelAnschrift.text = [NSString stringWithFormat:#"%#", adresse.anschrift2];
} else {
cell.labelAnschrift.text = adresse.anschrift2;
}
cell.labelStrassePlzOrt.text = [NSString stringWithFormat:#"%#, %# %#", adresse.strasse, adresse.plz, adresse.ort];
}
}
cell.labelObjektnummer.text = [[object valueForKey:#"objektnr"] description];
cell.labelFilale.text = [NSString stringWithFormat:#"Filiale: %#, %#", object.filialname, object.objektanleger];
cell.labelAnrufer.text = [NSString stringWithFormat:#"Anrufer: %#", object.anrufer];
NSDate *rawSchadenstag = [object valueForKey:#"schadentag"];
NSDateFormatter *dateFormatterSchadenstag = [[NSDateFormatter alloc] init];
[dateFormatterSchadenstag setDateFormat:#"dd.MM.yyyy"];
cell.labelSchadentag.text = [NSString stringWithFormat:#"Schadenstag: %#", [dateFormatterSchadenstag stringFromDate:rawSchadenstag]];
cell.labelSchadensursache.text = [NSString stringWithFormat:#"Schadensursache: %#", object.schadensursache];
cell.labelSchadensursache.lineBreakMode = NSLineBreakByWordWrapping;
cell.labelSchadensursache.numberOfLines = 2;
NSString *strWeitererHinweis;
if (nil != object.weitererhinweis)
{
strWeitererHinweis = object.weitererhinweis;
}
else
{
strWeitererHinweis = #"Es sind keine weiteren Hinweise vorhanden";
}
cell.labelWeitererHinweis.text = [NSString stringWithFormat:#"Weiterer Hinweis: %#", strWeitererHinweis];
cell.labelWeitererHinweis.numberOfLines = 3;
cell.labelWeitererHinweis.lineBreakMode = NSLineBreakByWordWrapping;
int intTerminart = [object.terminart intValue];
switch (intTerminart) {
case 1: {
cell.backgroundColor = [UIColor whiteColor];
[cell.buttonUpload setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
break;
}
case 2: {
cell.backgroundColor = [UIColor blueColor];
[cell.buttonUpload setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
break;
}
case 4: {
cell.backgroundColor = [UIColor redColor];
[cell.buttonUpload setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
break;
}
case 5: {
cell.backgroundColor = [UIColor yellowColor];
[cell.buttonUpload setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
break;
}
case 6: {
cell.backgroundColor = [UIColor greenColor];
[cell.buttonUpload setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
break;
}
default:
break;
}
cell.selectionStyle = UITableViewCellSelectionStyleGray;
BOOL checked = [self checkObjekt:object];
if (checked == YES ) {
[cell.buttonUpload setHidden:NO];
[cell.buttonUpload setTitle:#"Geprüft, Upload!" forState:UIControlStateNormal];
[cell.buttonUpload setEnabled:YES];
} else {
[cell.buttonUpload setHidden:NO];
[cell.buttonUpload setTitle:#"Ungeprüft" forState:UIControlStateNormal];
[cell.buttonUpload setEnabled:YES];
}
}
Here is the checkObjekt Function:
- (BOOL)checkObjekt:(Objekt *)objekt {
if ([[objekt.wohneinheiten allObjects] count] == 0) {
return NO;
}
//Das Schadensformular für jede Wohneinheit wird in einer Schleife durchgearbeitet
for (Wohneinheit *wohneinheit in [objekt.wohneinheiten allObjects])
{
MbsAppDelegate *delegate = (MbsAppDelegate *)[[UIApplication sharedApplication] delegate];
NSEntityDescription *entityDescription = nil;
//Auswahl der richtigen Tabelle anhand der Terminart
if ([objekt.terminart integerValue] == 1)
{
entityDescription = [NSEntityDescription entityForName:#"Schaden" inManagedObjectContext:delegate.managedObjectContext];
}
else if ([objekt.terminart integerValue] == 2)
{
entityDescription = [NSEntityDescription entityForName:#"Leckortung" inManagedObjectContext:delegate.managedObjectContext];
}
else if ([objekt.terminart integerValue] == 4)
{
entityDescription = [NSEntityDescription entityForName:#"Aufbau" inManagedObjectContext:delegate.managedObjectContext];
}
else if ([objekt.terminart integerValue] == 5)
{
entityDescription = [NSEntityDescription entityForName:#"Zwischenmessung" inManagedObjectContext:delegate.managedObjectContext];
}
else if ([objekt.terminart integerValue] == 6)
{
entityDescription = [NSEntityDescription entityForName:#"Abbau" inManagedObjectContext:delegate.managedObjectContext];
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"wohneinheit == %#", wohneinheit];
[request setPredicate:predicate];
NSError *error;
NSArray *items = [delegate.managedObjectContext executeFetchRequest:request error:&error];
if (items == nil || [items count] != 1)
{
//Wenn kein Schadens- oder Leckortungsformular vorhanden ist, dann wird NO zurückgegeben
return NO;
}
else
{
//Durchlaufen der einzelnen Checked Spalten.
for (id item in items) {
int tempChecked = 0;
NSArray *checkedColumns = nil;
if ([objekt.terminart integerValue] == 1)
{
checkedColumns = self.checkedColumnsTerminart1;
}
else if ([objekt.terminart integerValue] == 2)
{
checkedColumns = self.checkedColumnsTerminart2;
}
else if ([objekt.terminart integerValue] == 4)
{
checkedColumns = self.checkedColumnsTerminart4;
}
else if ([objekt.terminart integerValue] == 5)
{
checkedColumns = self.checkedColumnsTerminart5;
}
else if ([objekt.terminart integerValue] == 6)
{
checkedColumns = self.checkedColumnsTerminart6;
}
for (NSString *checkedColumn in checkedColumns)
{
NSManagedObject *managedObject = (NSManagedObject *)item;
NSDictionary * attributes = [[managedObject entity] attributesByName];
NSArray *allKeys = [attributes allKeys];
if ([allKeys containsObject:checkedColumn]) {
NSNumber *checkedColumnValue = (NSNumber *)[item valueForKey:checkedColumn];
if (checkedColumnValue != [NSNumber numberWithInt:1]) {
tempChecked = 0;
}
else
{
tempChecked = 1;
}
} else {
tempChecked = 1;
}
}
if(tempChecked == 0)
{
return NO;
}
else
{
return YES;
}
}
}
}
return YES;
}
I implemented “swipe to delete cell in TableView” and it works fine in iOS 7 but that same code is not working for iOS 8. Is there any changes done for iOS 8 in this?
After swiping the cell I see nothing in my “Groups” section in iOS 8 while in iOS 7 I see a delete button.
Here is the code I am using:
- (void)swipeableTableViewCell:(SWTableViewCell *)cell scrollingToState: (SWCellState)state
{
switch (state) {
case 0:
NSLog(#"utility buttons closed");
[customDropDown hideDropDown:dropDownFrame];
[customDropDown removeFromSuperview];
customDropDown = nil;
break;
case 1:
NSLog(#"left utility buttons open");
break;
case 2:
NSLog(#"right utility buttons open");
break;
default:
break;
}
}
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index
{
switch (index)
{
case 0:
{
if (cell.rightUtilityButtons.count == 1)
{
NSArray * arr = [[NSArray alloc] init];
arr = [NSArray arrayWithArray:[self.groupsInfoDict allKeys]];
if(customDropDown == nil)
{
indexPathForSelectedcontact = [self.groupListTableView indexPathForCell:cell];
CGRect frame = [self.groupListTableView rectForRowAtIndexPath:indexPathForSelectedcontact];
CGRect animatedViewFrame = [self.view convertRect:frame fromView:self.groupListTableView];
CGFloat height = self.view.frame.size.height-(animatedViewFrame.origin.y+44);
NSString* direction;
if (height<88)
{
direction = #"up";
CGFloat noOfRowHeight = [arr count]*40;
if (noOfRowHeight <animatedViewFrame.origin.y)
{
height = noOfRowHeight;
}
else
{
height = animatedViewFrame.origin.y;
}
}
else
{
direction = #"down";
CGFloat noOfRowHeight = [arr count]*40;
if (noOfRowHeight <height)
{
height = noOfRowHeight;
}
}
dropDownFrame = CGRectMake(animatedViewFrame.origin.x, animatedViewFrame.origin.y, 160,height);
customDropDown = [[CustomDropDown alloc]showDropDown:dropDownFrame arrayOfData:arr ArrayOfimages:nil inDirection:direction onView:self.view];
customDropDown.delegate = self;
}
else
{
[customDropDown hideDropDown:dropDownFrame];
[customDropDown removeFromSuperview];
dropDownFrame = CGRectZero;
customDropDown = nil;
}
}
else
{
NSIndexPath* indexpath = [self.groupListTableView indexPathForCell:cell];
NSArray* arrayOfKeys = (NSArray *)self.groupsInfoDict.allKeys;
NSArray *sortedValues = [arrayOfKeys sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)];
groupTitleSelectedForRename = [sortedValues objectAtIndex:indexpath.row];
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Events" bundle:nil];
AddANewGroupViewController *addANewGroupViewController = [storyboard instantiateViewControllerWithIdentifier:#"AddANewGroupViewController"];
addANewGroupViewController.screenType = kScreenEditGroup;
addANewGroupViewController.useTableIndex = YES;
addANewGroupViewController.allowSearchControl = YES;
addANewGroupViewController.groupTitleSelectedForRename = groupTitleSelectedForRename;
[self.navigationController pushViewController:addANewGroupViewController animated:YES];
//[self getGroupNameAlert:groupTitleSelectedForRename ifAlreadyExists:NO];
}
break;
}
case 1:
{
NSIndexPath* indexPath = [self.groupListTableView indexPathForCell:cell];
// Change the cell appearance
NSArray* arrayOfKeys = (NSArray *)self.groupsInfoDict.allKeys;
NSArray *sortedValues = [arrayOfKeys sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)];
selectedGroupKey = [sortedValues objectAtIndex:indexPath.row];
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Are you sure you want to delete this group?" delegate:self cancelButtonTitle:#"NO" otherButtonTitles:#"YES", nil];
[alert setTag:990];
[alert show];
break;
}
default:
break;
}
}
- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell
{
// allow just one cell's utility button to be open at once
return YES;
}
- (BOOL)swipeableTableViewCell:(SWTableViewCell *)cell canSwipeToState:(SWCellState)state{
switch (state) {
case 1:
// set to NO to disable all left utility buttons appearing
return YES;
break;
case 2:
// set to NO to disable all right utility buttons appearing
return YES;
break;
default:
break;
}
return YES;
}
*This is the whole code :)
I have been trying to fix this for an hour now, but i can still not make it.
I would be happy if someone could help me :)
Still can't make the UI_USER_INTERFACE_IDIOM code work.*
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
-(void)Collision{
if (CGRectIntersectsRect(Heli.frame, Obstacle.frame)) {
[self EndGame];
}
if (CGRectIntersectsRect(Heli.frame, Obstacle2.frame)) {
[self EndGame];
}
if (CGRectIntersectsRect(Heli.frame, Bottom1.frame)) {
[self EndGame];
}
if (CGRectIntersectsRect(Heli.frame, Top1.frame)) {
[self EndGame];
}
}
-(void)EndGame{
if (Scorenumber > HighScore) {
HighScore = Scorenumber;
[[NSUserDefaults standardUserDefaults] setInteger:HighScore
forKey:#"HighScoreSaved"];
}
Heli.hidden = YES;
[timer invalidate];
[Scorer invalidate];
[self performSelector:#selector(NewGame) withObject: nil afterDelay:2];
}
-(void)NewGame{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
// For iPhone
Bottom1.hidden = YES;
Top1.hidden = YES;
Obstacle.hidden = YES;
Obstacle2.hidden = YES;
corona.hidden = YES;
Intro1.hidden = NO;
Intro2.hidden = NO;
Intro3.hidden = NO;
Heli.hidden = NO;
Heli.center = CGPointMake(88, 286);
Heli.image = [UIImage imageNamed:#"buss til app opp.png"];
Start = YES;
Scorenumber = 0;
Score.text = [NSString stringWithFormat:#"Score: 0"];
Intro3.text = [NSString stringWithFormat:#"HighScore: %i", HighScore];
}
} else{
// For iPad
Bottom1.hidden = YES;
Top1.hidden = YES;
Obstacle.hidden = YES;
Obstacle2.hidden = YES;
corona.hidden = YES;
Intro1.hidden = NO;
Intro2.hidden = NO;
Intro3.hidden = NO;
Heli.hidden = NO;
Heli.center = CGPointMake(153, 515);
Heli.image = [UIImage imageNamed:#"buss til app opp.png"];
Start = YES;
Scorenumber = 0;
Score.text = [NSString stringWithFormat:#"Score: 0"];
Intro3.text = [NSString stringWithFormat:#"HighScore: %i", HighScore];
Just look at following code:
-(void)NewGame{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
// For iPhone
Bottom1.hidden = YES;
Top1.hidden = YES;
Obstacle.hidden = YES;
Obstacle2.hidden = YES;
corona.hidden = YES;
Intro1.hidden = NO;
Intro2.hidden = NO;
Intro3.hidden = NO;
Heli.hidden = NO;
Heli.center = CGPointMake(88, 286);
Heli.image = [UIImage imageNamed:#"buss til app opp.png"];
Start = YES;
Scorenumber = 0;
Score.text = [NSString stringWithFormat:#"Score: 0"];
Intro3.text = [NSString stringWithFormat:#"HighScore: %i", HighScore];
}
} else{
and see - "}" symbol on line before "} else{" is wrong. It is the pair for
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
opening construction, so "else" is "standalone - it is wrong.
Try to delete this "}".