135 lines
4.7 KiB
Objective-C
135 lines
4.7 KiB
Objective-C
//
|
||
// PetStoresViewController.m
|
||
// Ifish
|
||
//
|
||
// Created by 祝发冬 on 2020/4/19.
|
||
// Copyright © 2020 lianlian. All rights reserved.
|
||
//
|
||
|
||
#import "PetStoresViewController.h"
|
||
#import "IfishDataUnity.h"
|
||
#import "IfishDeviceInfo.h"
|
||
|
||
@interface PetStoresViewController ()
|
||
|
||
@end
|
||
|
||
@implementation PetStoresViewController
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
[self addTitleViewWithTitle:self.store.deviceName];
|
||
// Do any additional setup after loading the view from its nib.
|
||
}
|
||
-(void)addTitleViewWithTitle:(NSString *)title
|
||
{
|
||
UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
|
||
button.frame=CGRectMake(0, 0, kSizeFrom750(300), 44);
|
||
[button setTitle:title forState:UIControlStateNormal];
|
||
button.titleLabel.font=[UIFont systemFontOfSize:19];
|
||
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||
[button addTarget:self action:@selector(changeStoreName:) forControlEvents:UIControlEventTouchUpInside];
|
||
|
||
|
||
|
||
self.navigationItem.titleView=button;
|
||
}
|
||
-(void)changeStoreName:(UIButton*)button
|
||
{
|
||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"修改名称" message:nil preferredStyle:UIAlertControllerStyleAlert];
|
||
|
||
|
||
//增加确定按钮;
|
||
[alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
||
//获取第1个输入框;
|
||
UITextField *passTextField = alertController.textFields.firstObject;
|
||
|
||
|
||
NSString*name=passTextField.text;
|
||
if (name.length)
|
||
{
|
||
NSString*url=[NSString stringWithFormat:@"%@/api/user/updatePetStore.do",JIEKOUPORT];
|
||
UserModel*model=[dataContorl getUserInfo];
|
||
|
||
|
||
[AFHttpTool requestWihtMethod:RequestMethodTypePost url:url params:@{@"userId":model.userId,@"oldName":self.store.deviceName,@"newName":name} success:^(id response) {
|
||
|
||
|
||
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
|
||
NSLog(@"data:%@",resultDic[@"data"]);
|
||
;
|
||
if ([resultDic[@"result"] isEqualToString:@"100"]) {
|
||
|
||
[self.view makeToast:@"修改成功"];
|
||
self.store.deviceName=name;
|
||
[self addTitleViewWithTitle:name];
|
||
[[NSNotificationCenter defaultCenter]postNotificationName:@"updateUserInfobyValidation" object:nil];
|
||
}
|
||
else
|
||
{
|
||
[self.view makeToast:@"修改失败"];
|
||
}
|
||
|
||
} failure:^(NSError *err) {
|
||
[self.view makeToast:@"修改失败"];
|
||
}];
|
||
}
|
||
else
|
||
{
|
||
[self.view makeToast:@"名字不能为空"];
|
||
}
|
||
|
||
|
||
|
||
|
||
}]];
|
||
[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
||
}]];
|
||
|
||
|
||
|
||
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
|
||
|
||
textField.text = self.store.deviceName;
|
||
|
||
}];
|
||
|
||
[self presentViewController:alertController animated:true completion:nil];
|
||
}
|
||
|
||
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||
{
|
||
return self.store.list.count;
|
||
}
|
||
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||
{
|
||
UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"pets"];
|
||
DeviceModel*model= self.store.list[indexPath.row];
|
||
if (!cell)
|
||
{
|
||
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"pets"];
|
||
}
|
||
cell.textLabel.text=model.showName;
|
||
return cell;
|
||
}
|
||
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||
{
|
||
DeviceModel*model= self.store.list[indexPath.row];
|
||
[[Socketsingleton sharedInstance] cutOffSocket];
|
||
[[IfishDataUnity shareDataInstance] initAppCenterVcWith:model addWithdissMisVc:nil];
|
||
[[DataCenter defaultDtacenter].cache setString:model.macAddress forKey:@"currentPetDevice"];
|
||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||
}
|
||
|
||
/*
|
||
#pragma mark - Navigation
|
||
|
||
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
||
// Get the new view controller using [segue destinationViewController].
|
||
// Pass the selected object to the new view controller.
|
||
}
|
||
*/
|
||
|
||
@end
|