I'm currently working on a view where a player can choose a character to play with. I have a tableView where each row represents a character. Inside each row is a button that a player taps to select that respective character. The first time a user loads it, only one character is available (first row) and I do the following in viewDidLoad:
//If not selected character exists set it to the default character
if (![[NSUserDefaults standardUserDefaults] integerForKey:#"Current Character"]) {
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:#"Current Character"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
NSLog(#"Value: %d", [[NSUserDefaults standardUserDefaults] integerForKey:#"Current Character"]);
By default all of the buttons in each row are hidden revealing a lock image behind it. So I do the following in the cellForRowAtIndexPath method:
//CHECK FOR UNLOCKED ITEMS
switch (indexPath.row) {
case 0: {
//Always show since it will always be available
cell.playerButton.hidden = NO;
break;
}
case 1: {
if([[NSUserDefaults standardUserDefaults] boolForKey:#"item2Unlocked"]) {
cell.playerButton.hidden = NO;
} else {
cell.playerButton.hidden = YES;
}
break;
}
case 2: {
if([[NSUserDefaults standardUserDefaults] boolForKey:#"item3Unlocked"]) {
cell.playerButton.hidden = NO;
} else {
cell.playerButton.hidden = YES;
}
break;
}
case 3: {
if([[NSUserDefaults standardUserDefaults] boolForKey:#"item4Unlocked"]) {
cell.playerButton.hidden = NO;
} else {
cell.playerButton.hidden = YES;
}
break;
}
default:
break;
}
Everything is working great so far. The problem that I'm facing is figuring out how to update the button in the correct row to a selected state. I've tried doing the following, but it ends up updating more than one button:
//CHECK FOR UNLOCKED ITEMS
switch (indexPath.row) {
case 0: {
cell.playerButton.hidden = NO;
if ([[NSUserDefaults standardUserDefaults] integerForKey:#"Current Character"] == 0) {
cell.playerButton.selected = YES;
} else {
cell.playerButton.selected = NO;
}
break;
}
case 1: {
if([[NSUserDefaults standardUserDefaults] boolForKey:#"item1Unlocked"]) {
cell.playerButton.hidden = NO;
if ([[NSUserDefaults standardUserDefaults] integerForKey:#"Current Character"] == 1) {
cell.playerButton.selected = YES;
} else {
cell.playerButton.selected = NO;
}
} else {
cell.playerButton.hidden = YES;
}
break;
}
case 2: {
if([[NSUserDefaults standardUserDefaults] boolForKey:#"item2Unlocked"]) {
cell.playerButton.hidden = NO;
if ([[NSUserDefaults standardUserDefaults] integerForKey:#"Current Character"] == 2) {
cell.playerButton.selected = YES;
} else {
cell.playerButton.selected = NO;
}
} else {
cell.playerButton.hidden = YES;
}
break;
}
case 3: {
if([[NSUserDefaults standardUserDefaults] boolForKey:#"item3Unlocked"]) {
cell.playerButton.hidden = NO;
if ([[NSUserDefaults standardUserDefaults] integerForKey:#"Current Character"] == 3) {
cell.playerButton.selected = YES;
} else {
cell.playerButton.selected = NO;
}
} else {
cell.playerButton.hidden = YES;
}
break;
}
default:
break;
}
What's wrong here?
UPDATE
Doing the following, the selected state finally worked:
//CHECK FOR UNLOCKED ITEMS
switch (indexPath.row) {
case 0: {
cell.playerButton.hidden = NO;
if ([[NSUserDefaults standardUserDefaults] integerForKey:#"Current Character"] == 0) {
cell.playerButton.selected = YES;
NSLog(#"Character is selected.");
} else {
cell.playerButton.selected = NO;
}
break;
}
case 1: {
if([[NSUserDefaults standardUserDefaults] boolForKey:#"item1Unlocked"]) {
cell.playerButton.hidden = NO;
if ([[NSUserDefaults standardUserDefaults] integerForKey:#"Current Character"] == 1) {
cell.playerButton.selected = YES;
NSLog(#"Character B is selected.");
} else {
cell.playerButton.selected = NO;
}
} else {
cell.playerButton.hidden = YES;
}
break;
}
case 2: {
if([[NSUserDefaults standardUserDefaults] boolForKey:#"item3Unlocked"]) {
cell.playerButton.hidden = NO;
if ([[NSUserDefaults standardUserDefaults] integerForKey:#"Current Character"] == 2) {
cell.playerButton.selected = YES;
NSLog(#"character C is selected.");
} else {
cell.playerButton.selected = NO;
}
} else {
cell.playerButton.hidden = YES;
}
break;
}
case 3: {
if([[NSUserDefaults standardUserDefaults] boolForKey:#"item4Unlocked"]) {
cell.playerButton.hidden = NO;
if ([[NSUserDefaults standardUserDefaults] integerForKey:#"Current Character"] == 3) {
cell.playerButton.selected = YES;
NSLog(#"Character D is selected.");
} else {
cell.playerButton.selected = NO;
}
} else {
cell.playerButton.hidden = YES;
}
break;
}
default:
break;
}
However how can I disable the button or user interaction if button is selected?
This should do the same thing and is a lot simpler
//CHECK FOR UNLOCKED ITEMS
int currentCharacter=[[NSUserDefaults standardUserDefaults] integerForKey:#"Current Character"];
BOOL unlocked=NO;
if (indexPath.row == 0)
{
unlocked=YES; // Character 0 is always unlocked
}
else {
unlocked=[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:"%#item%dUnlocked",indexPath.row]]
}
if (unlocked)
{
cell.playerButton.hidden=NO;
if (indexPath.row == currentCharacter)
{
cell.playerButton.selected=YES;
cell.playerButton.enabled=NO; //Cannot select if already selected
}
else
{
cell.playerButton.selected=NO;
cell.playerButton.enabled=YES;
}
}
else
{
cell.playerButton.hidden=YES;
}
Related
This Application sends data (through a dictionary) two following instances to other views from the sender.
Home Page TableviewCell to each particular view according to each state
Ex- IF state 1 - AppointmentView 2 - OnthewayView 3 - TimerView 4 - Invoice View.
Home ---> Appointment
Home ---> ontheWay
Home ---> TimerView
Home ---> Invoice
Home ---> AppointmentView ---> ontheway --> timer ---> Invoice
I have an issue when I navigating timer --> Invoice the timer going as empty timer = "" so some of my functions (time fee calculation) are not working on this instance only.
But the same as 1st instance when I go back to Home and Home -> invoice timer=10 and rest of the functions works.
code snippet for 1st instance (the working one) (homeviewcontroller)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
if (bookingArray.count) {
NSInteger keyStatus =[bookingArray[indexPath.row][#"status"] integerValue] ;
switch (keyStatus) {
case 2:
[self performSegueWithIdentifier:#"appointmentDetail" sender:bookingArray[indexPath.row]];
break;
case 5:
[self performSegueWithIdentifier:#"ToMapController" sender:bookingArray[indexPath.row]];
break;
case 6:
[self performSegueWithIdentifier:#"ToTimerVC" sender:bookingArray[indexPath.row]];
break;
case 21:
[self performSegueWithIdentifier:#"ToTimerVC" sender:bookingArray[indexPath.row]];
break;
case 22:
[self performSegueWithIdentifier:#"ToInvoice" sender:bookingArray[indexPath.row]];
break;
}
Second instance (Not working) (timerViewController)
-(void)onTHEWAYButtonTapped
{
self.navigationItem.leftBarButtonItem.enabled = NO;
[[ProgressIndicator sharedInstance]showPIOnView:self.view withMessage:NSLocalizedString(#"Loading..",#"Loading..")];
switch (_bookingStatu) {
case 2:
case 5:
case 21:{
_bookingStatu = 6;
break;
}
case 6:{
_bookingStatu = 22;
break;
}
default:
break;
}
NSDictionary *parameters;
if (_bookingStatu==6) {
parameters = #{
kSMPcheckUserSessionToken: [[NSUserDefaults standardUserDefaults] objectForKey:KDAcheckUserSessionToken],
kSMPCommonDevideId :[[NSUserDefaults standardUserDefaults] objectForKey:kPMDDeviceIdKey],
#"ent_appnt_dt" :self.dictBookingDetails[#"apntDt"],
KSMPPatientEmail :self.dictBookingDetails[#"email"],
kSMPRespondResponse :[NSString stringWithFormat:#"%ld",(long)_bookingStatu],
#"ent_date_time" :[Helper getCurrentDateTime],
#"ent_bid" :self.dictBookingDetails[#"bid"],
#"bookingId" :_dictBookingDetails[#"bid"],
#"technicianId" :[[NSUserDefaults standardUserDefaults] objectForKey:#"ProviderId"],
#"latitude" :_dictBookingDetails[#"apptLat"],
#"longitude" :_dictBookingDetails[#"apptLong"]
//temp test
};
NSLog(#"Check the sent param-1%#",parameters);
}else if (_bookingStatu==22) {
parameters = #{
kSMPcheckUserSessionToken: [[NSUserDefaults standardUserDefaults] objectForKey:KDAcheckUserSessionToken],
kSMPCommonDevideId :[[NSUserDefaults standardUserDefaults] objectForKey:kPMDDeviceIdKey],
#"ent_appnt_dt" :self.dictBookingDetails[#"apntDt"],
KSMPPatientEmail :self.dictBookingDetails[#"email"],
kSMPRespondResponse :[NSString stringWithFormat:#"%ld",(long)_bookingStatu],
#"ent_date_time" :[Helper getCurrentDateTime],
#"ent_bid" :self.dictBookingDetails[#"bid"],
#"ent_timer":[NSString stringWithFormat:#"%d",(timeHr*3600)+(timeMin*60)+timeSec],
#"bookingId" :_dictBookingDetails[#"bid"],
#"technicianId" :[[NSUserDefaults standardUserDefaults] objectForKey:#"ProviderId"],
#"latitude" :_dictBookingDetails[#"apptLat"],
#"longitude" :_dictBookingDetails[#"apptLong"],
};
NSLog(#"Check the sent param-2%#",parameters);
}
NetworkHandler *handler = [NetworkHandler sharedInstance];
[handler composeRequestWithMethod:MethodupdateApptStatus
paramas:parameters
onComplition:^(BOOL succeeded, NSDictionary *response) {
[[ProgressIndicator sharedInstance]hideProgressIndicator];
[_customSliderView sliderImageOrigin];
if (succeeded) {
if ([response[#"errFlag"] isEqualToString:#"1"]) {
[Helper showAlertWithTitle:NSLocalizedString(#"Message", #"Message") Message:response[#"errMsg"]];
if([[response objectForKey:#"errNum"] intValue] == 41){
[Helper showAlertWithTitle:NSLocalizedString(#"Error",#"Error") Message:[response objectForKey:#"errMsg"]];
[self backButtonPressed];
}else if ([[response objectForKey:#"errNum"] intValue] == 83){
[self userSessionTokenExpire];
}
}else{
[self emitTheBookingACk:_bookingStatu];
[self updateCustomerinfo];
if (_bookingStatu==22) {
[self getTimerAPI];
[self performSegueWithIdentifier:#"toInvoiceSegue" sender:_dictBookingDetails];
}else if (_bookingStatu==6){
[self pauseTimer:nil];
}
}
}
else
{
NSLog(#"Error");
[[ProgressIndicator sharedInstance] hideProgressIndicator];
}
}];
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"toReportView"])
{
RecomReportViewController *reportView = (RecomReportViewController *)segue.destinationViewController;
reportView.bookingId = bookingID;
reportView.taskLocation = taskLocation;
}
else if([[segue identifier] isEqualToString:#"toInvoiceSegue"])
{
InvoiceViewController *details =[segue destinationViewController];
details.minutesCount=[NSString stringWithFormat:#"%d",(timeHr*3600)+(timeMin*60)+timeSec];
details.currentTimer = timerfinished;
[self getTimerAPI];
details.dictBookingDetails = sender;
}
return;
InvoiceViewController.m
—
- (void)viewDidLoad {
[super viewDidLoad];
//sending request to get materialfee
NSString *testTimer = _dictBookingDetails[#"timer"];
}
Please help me to find out the bug and fix the issue...
I have inherited a old iOS project that was created back in 2012 and is using some really old school techniques. I converted from 32 bit to 64 bit.
On the settings screens, the height of the settings items are not tall enough, causing the settings pages to look jumbled.
Any idea what is making this happen?
This page has no xib file, it's generated in code.
#import "GeneralSettings.h"
//preference keys
#define kGENERAL_ACCOUNT #"general_account"
#define kGENERAL_EXPAND_RESULTS #"general_expand_results"
#define kGENERAL_FINALS_ONLY #"general_finals_only"
#define kGENERAL_SEARCH_DAYS #"general_search_days"
#define kGENERAL_STARTUP #"general_startup"
#interface GeneralSettings ()
#end
#implementation GeneralSettings
+ (NSString *)accountNumber {
return [[NSUserDefaults standardUserDefaults]
objectForKey:kGENERAL_ACCOUNT];
}
+ (BOOL)expandResults {
NSString *expandResults = [[NSUserDefaults standardUserDefaults]
objectForKey:kGENERAL_EXPAND_RESULTS];
return expandResults ? [expandResults boolValue] : YES;
}
+ (BOOL)finalsOnly {
return [[NSUserDefaults standardUserDefaults]
boolForKey:kGENERAL_FINALS_ONLY];
}
+ (NSInteger)numberOfDays {
NSString *numberOfDays = [[NSUserDefaults standardUserDefaults]
objectForKey:kGENERAL_SEARCH_DAYS];
if (numberOfDays) {
if (([numberOfDays integerValue] != 90) || [Globals
sharedInstance].isQA) {
return [numberOfDays integerValue];
}
//value of 90 lingering from QA session, reset to 15
[[NSUserDefaults standardUserDefaults] setValue:#"15"
forKey:kGENERAL_SEARCH_DAYS];
return 15;
}
//default value
return 7;
}
+ (NSInteger)showAtStartup {
return [[NSUserDefaults standardUserDefaults]
integerForKey:kGENERAL_STARTUP];
}
+ (void)setAccountNumber:(NSString *)accountNumber {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setValue:accountNumber forKey:kGENERAL_ACCOUNT];
[prefs synchronize];
}
+ (void)convert {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if ([prefs objectForKey:#"finalsOnly"]) {
BOOL value = [prefs boolForKey:#"finalsOnly"];
[prefs removeObjectForKey:#"finalsOnly"];
[prefs setBool:value forKey:kGENERAL_FINALS_ONLY];
[prefs synchronize];
}
if ([prefs objectForKey:#"searchDays"]) {
NSString *value = [prefs objectForKey:#"searchDays"];
int index = 2;
if ([value isEqualToString:#"1 Days"]) {
index = 0;
}
else if ([value isEqualToString:#"3 Days"]) {
index = 1;
}
else if ([value isEqualToString:#"15 Days"]) {
index = 3;
}
[prefs removeObjectForKey:#"searchDays"];
[prefs setInteger:index forKey:kGENERAL_SEARCH_DAYS];
[prefs synchronize];
}
if ([prefs objectForKey:#"showAtStartup"]) {
NSString *value = [prefs objectForKey:#"showAtStartup"];
int index = 0;
if ([value isEqualToString:#"Contacts"]) {
index = 1;
}
else if ([value isEqualToString:#"Lookup Test"]) {
index = 2;
}
[prefs removeObjectForKey:#"showAtStartup"];
[prefs setInteger:index forKey:kGENERAL_STARTUP];
[prefs synchronize];
}
}
- (id)init {
self = [super initWithTitle:xGeneralSettings withIconName:#"icon-
settings-general.png"];
if (self) {
//initialization
Globals *globals = [Globals sharedInstance];
SettingsSection *section = [self.sections objectAtIndex:0];
//add account settings section
SettingsSection *accountSection = [[[SettingsSection alloc]
initWithTitle:xAccountSettings] autorelease];
[self.sections addObject:accountSection];
//create settings
Setting *startupSetting = [[[Setting alloc]
initWithKey:kGENERAL_STARTUP withTitle:xGeneralStartupTitle
withType:pickerSetting] autorelease];
SearchDaysSetting *searchDaysSetting = [[[SearchDaysSetting alloc]
initWithKey:kGENERAL_SEARCH_DAYS withTitle:xGeneralSearchDaysTitle
withType:pickerSetting] autorelease];
Setting *finalsSetting = [[[Setting alloc]
initWithKey:kGENERAL_FINALS_ONLY withTitle:xGeneralFinalsOnlyTitle
withType:toggleSetting] autorelease];
Setting *expandSetting = [[[Setting alloc]
initWithKey:kGENERAL_EXPAND_RESULTS
withTitle:xGeneralExpandResultsTitle withType:toggleSetting] autorelease];
AccountSetting *accountSetting = [[[AccountSetting alloc]
initWithKey:kGENERAL_ACCOUNT withTitle:xGeneralAccountTitle
withType:pickerSetting] autorelease];
//set setting parameters
[startupSetting setPickerValuesFromString:xGeneralStartupValues
withDefaultValue:0];
[searchDaysSetting
setPickerValuesFromString:xGeneralSearchDaysValues withDefaultValue:2];
[finalsSetting setToggle:NO
withSummary:xGeneralFinalsOnlySummary];
[expandSetting setToggle:YES
withSummary:xGeneralExpandResultsSummary];
[accountSetting setPickerValues:[globals allAccounts]
withDefaultValue:[globals defaultAccount]];
if ([Globals sharedInstance].isQA) {
[searchDaysSetting.pickerValues addObject:#"90 Days"];
}
//add settings to sections
[section.settings addObject:startupSetting];
[section.settings addObject:searchDaysSetting];
[section.settings addObject:finalsSetting];
[section.settings addObject:expandSetting];
[accountSection.settings addObject:accountSetting];
}
return self;
}
#end
#pragma mark - AccountSetting class
#implementation AccountSetting
- (NSInteger)intValue {
NSArray *picklist = self.pickerValues;
NSString *value = [self stringValue];
//return the index of our value
for (int i = 0; i < picklist.count; i++) {
if ([[picklist objectAtIndex:i] isEqualToString:value]) {
return i;
}
}
return [super intValue];
}
- (void)setInteger:(NSInteger)index shouldSave:(BOOL)saveValue {
NSArray *picklist = self.pickerValues;
if ((index > -1) && (index < picklist.count)) {
//save the value determined by this index
[self setString:[picklist objectAtIndex:index]
shouldSave:saveValue];
}
}
#end
#pragma mark - AccountSetting class
#implementation SearchDaysSetting
- (NSInteger)intValue {
//return the index of our value
switch ([super intValue]) {
case 1:
return 0;
case 3:
return 1;
case 7:
return 2;
case 15:
return 3;
case 90:
return [self pickerValues].count - 1; //safe return of assumed index, which might not exist
}
return [[self defaultValue] integerValue];
}
- (void)setInteger:(NSInteger)index shouldSave:(BOOL)saveValue {
NSInteger numberOfDays = 7;
//save the value determined by this index
switch (index) {
case 0:
numberOfDays = 1;
break;
case 1:
numberOfDays = 3;
break;
case 2:
numberOfDays = 7;
break;
case 3:
numberOfDays = 15;
break;
case 4:
numberOfDays = 90;
break;
}
[super setInteger:numberOfDays shouldSave:saveValue];
}
#end
Try to look for UITableViewDataSource method:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 46;//here is height of cell
}
Or, add the following in viewDidLoad:
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 46;//here is height of cell
I am trying to call using Twilio sdk but my call is disconnected in 2 or 3 seconds. My Twilio account is upgrated. I am using below code
-(IBAction)mainButtonPressed:(id)sender
{
BasicPhoneAppDelegate* delegate = (BasicPhoneAppDelegate*)[UIApplication sharedApplication].delegate;
BasicPhone* basicPhone = delegate.phone;
if (!basicPhone.connection || basicPhone.connection.state == TCConnectionStateDisconnected)
{
NSString* strToNumber = self.textOutgoingDest.text;
if (strToNumber && ![strToNumber isEqualToString:#""]) {
switch (_eOutgoingType) {
case BPOutgoingNumber:
break;
case BPOutgoingClient:
strToNumber = [NSString stringWithFormat:#"client:%#", strToNumber];
break;
default:
break;
}
NSDictionary* dictParams = [NSDictionary dictionaryWithObjectsAndKeys:strToNumber, #"To", nil];
[self.phone connectWithParams:dictParams];
}
else {
[self.phone connectWithParams:nil];
}
}
else
{
[basicPhone disconnect];
}
[self syncMainButton];
}
I have solved my issue
-(IBAction)mainButtonPressed:(id)sender
{
BasicPhoneAppDelegate* delegate = (BasicPhoneAppDelegate*)[UIApplication sharedApplication].delegate;
BasicPhone* basicPhone = delegate.phone;
if (!basicPhone.connection || basicPhone.connection.state == TCConnectionStateDisconnected)
{
NSString* strToNumber = self.textOutgoingDest.text;
if (strToNumber && ![strToNumber isEqualToString:#""])
{
strToNumber = [NSString stringWithFormat:#"%#", strToNumber];
NSDictionary* dictParams = [NSDictionary dictionaryWithObjectsAndKeys:strToNumber, #"number", nil];
[self.phone connectWithParams:dictParams];
}
else
{
[self.phone connectWithParams:nil];
}
}
else
{
[basicPhone disconnect];
}
[self syncMainButton];
}
I'm plotting Real Time ECG using CorePlot library.When it uses in iPad air the performance is okay.But when i tried it with iPad mini, There is a delay in the plotting.I have done with collapseLayer and this link also.that didn't solved my problem.Can anyone suggest new solution for this.
My code is below:
-(void)newData:(NSTimer *)theTimer
{
for (int i =0;i<plotcount;i++){
if([Qrrch0 count]>0 || [Qrrch1 count]>0 || [Qrrch2 count]>0 || [Qrrch3 count]>0 || [Qrrspo2 count]>0 ){
if(g1==1 && thePlot){
currentIndex ++;
}
if(g2==1 && thePlot1){
currentIndex1 ++;
}
if(g3==1 && thePlot2){
currentIndex2 ++;
}
if(g4==1 && thePlot3){
currentIndex3 ++;
}
if(spo2==1 && thePlot4){
currentIndex4 ++;
}
if(arrayIndex>=kchannel1-1)
{
arrayIndex=0;
}
if(arrayIndex1>=kchannel2-1)
{
arrayIndex1=0;
}
if(arrayIndex>=kchannel1-1)
{
arrayIndex=0;
}
if(arrayIndex2>=kchannel3-1)
{
arrayIndex2=0;
}
if(arrayIndex3>=kchannel4-1)
{
arrayIndex3=0;
}
if(arrayIndex4>=kchannel5-1)
{
arrayIndex4=0;
}
if(g1==1 && thePlot){
currentIndex5++;
if(currentIndex5>=kchannel1)
{
if(arrayIndex==0)
{
[thePlot reloadDataInIndexRange:NSMakeRange(arrayIndex, arrayIndex)];
}else{
[thePlot deleteDataInIndexRange:NSMakeRange(arrayIndex, 1)];
}
}
if([Qrrch0 count]!=0)
{
arrPlot[arrayIndex]=[[Qrrch0 objectAtIndex:0] integerValue];
lastPlot0=[Qrrch0 objectAtIndex:0];
}else{
arrPlot[arrayIndex]=[lastPlot0 integerValue];
}
arrayIndex++;
}
if(g2==1 && thePlot1){
currentIndex6++;
if(currentIndex6>=kchannel2)
{
if(arrayIndex1==0)
{
[thePlot1 reloadDataInIndexRange:NSMakeRange(arrayIndex1, arrayIndex1)];
}else{
[thePlot1 deleteDataInIndexRange:NSMakeRange(arrayIndex1, 1)];
}
}
if([Qrrch1 count]!=0)
{
arrPlot1[arrayIndex1]=[[Qrrch1 objectAtIndex:0] integerValue];
lastPlot1=[Qrrch1 objectAtIndex:0];
}else{
arrPlot1[arrayIndex1]=[lastPlot1 integerValue];
}
arrayIndex1++;
}
if(g3==1 && thePlot2){
currentIndex7++;
if(currentIndex7>=kchannel3)
{
if(arrayIndex2==0)
{
[thePlot2 reloadDataInIndexRange:NSMakeRange(arrayIndex2, arrayIndex2)];
}else{
[thePlot2 deleteDataInIndexRange:NSMakeRange(arrayIndex2, 1)];
}
}
if([Qrrch2 count]!=0)
{
arrPlot2[arrayIndex2]=[[Qrrch2 objectAtIndex:0] integerValue];
lastPlot2=[Qrrch2 objectAtIndex:0];
}else{
arrPlot2[arrayIndex2]=[lastPlot2 integerValue];
}
arrayIndex2++;
}
if(g4==1 && thePlot3){
currentIndex8++;
if(currentIndex8>=kchannel4)
{
if(arrayIndex3==0)
{
[thePlot3 reloadDataInIndexRange:NSMakeRange(arrayIndex3, arrayIndex3)];
}else{
[thePlot3 deleteDataInIndexRange:NSMakeRange(arrayIndex3, 1)];
}
}
if([Qrrch3 count]!=0)
{
arrPlot3[arrayIndex3]=[[Qrrch3 objectAtIndex:0] integerValue];
lastPlot3=[Qrrch3 objectAtIndex:0];
}else{
arrPlot3[arrayIndex3]=[lastPlot3 integerValue];
}
arrayIndex3++;
}
if(spo2==1 && thePlot4){
currentIndex9++;
if(currentIndex9>=kchannel5)
{
if(arrayIndex4==0)
{
[thePlot4 reloadDataInIndexRange:NSMakeRange(arrayIndex4, arrayIndex4)];
}else{
[thePlot4 deleteDataInIndexRange:NSMakeRange(arrayIndex4, 1)];
}
}
if([Qrrspo2 count]!=0)
{
arrPlot4[arrayIndex4]=[[Qrrspo2 objectAtIndex:0] integerValue];
lastPlot4=[Qrrspo2 objectAtIndex:0];
}else{
arrPlot4[arrayIndex4]=[lastPlot4 integerValue];
}
arrayIndex4++;
}
if(g1==1 && thePlot){
if([Qrrch0 count]!=0)
{
[Qrrch0 removeObjectAtIndex:0];
}
if(currentIndex>=kchannel1)
{
currentIndex=1;
}
[thePlot insertDataAtIndex:currentIndex-1 numberOfRecords:1];
}
if(g2==1 && thePlot1){
if([Qrrch1 count]!=0)
{
[Qrrch1 removeObjectAtIndex:0];
}
if(currentIndex1>=kchannel2)
{
currentIndex1=1;
}
[thePlot1 insertDataAtIndex:currentIndex1-1 numberOfRecords:1];
}
if(g3==1 && thePlot2){
if([Qrrch2 count]!=0)
{
[Qrrch2 removeObjectAtIndex:0];
}
if(currentIndex2>=kchannel3)
{
currentIndex2=1;
}
[thePlot2 insertDataAtIndex:currentIndex2-1 numberOfRecords:1];
}
if(g4==1 && thePlot3){
if([Qrrch3 count]!=0)
{
[Qrrch3 removeObjectAtIndex:0];
}
if(currentIndex3>=kchannel4)
{
currentIndex3=1;
}
[thePlot3 insertDataAtIndex:currentIndex3-1 numberOfRecords:1];
}
if(spo2==1 && thePlot4){
if([Qrrspo2 count]!=0)
{
[Qrrspo2 removeObjectAtIndex:0];
}
if(currentIndex4>=kchannel5)
{
currentIndex4=1;
}
[thePlot4 insertDataAtIndex:currentIndex4-1 numberOfRecords:1];
}
}
else
{
[self datacha];
}
}
}
-(void) datacha{
NSArray *array;
if([FinalArray count]>0){
if(g1==1 && thePlot){
array = [[NSArray alloc] initWithArray:[FinalArray objectAtIndex:0]];
[Qrrch0 addObjectsFromArray:array];
}
if(g1==1 && thePlot){
[FinalArray removeObjectAtIndex:0];
}
}
if([FinalArray1 count]>0){
if(g2==1 && thePlot1){
array = [[NSArray alloc] initWithArray:[FinalArray1 objectAtIndex:0]];
[Qrrch1 addObjectsFromArray:array];
}
if(g2==1 && thePlot1){
[FinalArray1 removeObjectAtIndex:0];
}
}
if([FinalArray2 count]>0){
if(g3==1 && thePlot2){
array = [[NSArray alloc] initWithArray:[FinalArray2 objectAtIndex:0]];
[Qrrch2 addObjectsFromArray:array];
}
if(g3==1 && thePlot2){
[FinalArray2 removeObjectAtIndex:0];
}
} if([FinalArray3 count]>0){
if(g4==1 && thePlot3){
array = [[NSArray alloc] initWithArray:[FinalArray3 objectAtIndex:0]];
[Qrrch3 addObjectsFromArray:array];
}
if(g4==1 && thePlot3){
[FinalArray3 removeObjectAtIndex:0];
}
}
if([FinalArray4 count]>0){
if(spo2==1 && thePlot4){
array = [[NSArray alloc] initWithArray:[FinalArray4 objectAtIndex:0]];
[Qrrspo2 addObjectsFromArray:array];
}
if(spo2==1 && thePlot4){
[FinalArray4 removeObjectAtIndex:0];
}
}
}
#pragma mark -
#pragma mark Plot Data Source Methods
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
if(plot == thePlot)
{
if(currentIndex5>=kchannel1)
{
return kchannel1;
}else{
return currentIndex5;
}
}
if(plot == thePlot1)
{
if(currentIndex6>=kchannel2)
{
return kchannel2;
}else{
return currentIndex6;
}
}
if(plot == thePlot2)
{
if(currentIndex7>=kchannel3)
{
return kchannel3;
}else{
return currentIndex7;
}
}
if(plot == thePlot3)
{
if(currentIndex8>=kchannel4)
{
return kchannel4;
}else{
return currentIndex8;
}
}
if(plot == thePlot4)
{
if(currentIndex9>=kchannel5)
{
return kchannel5;
}else{
return currentIndex9;
}
}
return 0;
}
-(double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx{
double num;
NSString *textval = [NSString stringWithFormat:#"%d", countofpktloss];
self.losscount.text = textval;
switch ( fieldEnum ) {
case CPTScatterPlotFieldX:
if(plot == thePlot){
num =currentIndex;
}
else if(plot == thePlot1)
{
num = currentIndex1;
}
else if(plot == thePlot2)
{
num = currentIndex2;
}
else if(plot == thePlot3)
{
num = currentIndex3;
}
else if(plot == thePlot4)
{
num = currentIndex4;
}
break;
case CPTScatterPlotFieldY:
if(plot == thePlot){
num =arrPlot[idx];
}
else
if(plot == thePlot1){
num =arrPlot1[idx];
}
else if(plot == thePlot2){
num =arrPlot2[idx];
}
else if(plot == thePlot3)
{
num =arrPlot3[idx];
}
else if(plot == thePlot4)
{
num =arrPlot4[idx];
}
break;
default:
break;
}
return num;
}
The collapsesLayers property is there to help save memory for a static graph. Using it on a graph that updates frequently makes the performance worse since it requires the graph to redraw everything, not just the part that changed, e.g., the plot.
Added comments
Make sure the timer stops when you expect it to. Otherwise, it will keep adding points to the plots.
How often does the timer fire to add points to the plots? There's no point in updating the plots more than 60 times per second and you may need to reduce that further on older devices like the iPad 2 to get good performance with lots of data points. You can add more than one point in each update if needed.
Check the ranges used to reload data points. You're passing the same number as the location and length of the range. I suspect you mean to use a length of one (1) for each range. If so, you're reloading more data than required on each pass.
Have you tried looking at other chart libraries? SciChart provides an iOS chart tailored for realtime ECG applications. It's extremely fast and doesn't have the performance problems of Core plot.
See iOS Chart Performance Comparison
and SciChart iOS ECG demo
Disclosure, I am the tech lead on the scichart projects
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;
}