我有一个UITableView,它显示从连接WiFi的设备收到的数据.
我想做一个相当bog标准的手势响应,拖动一个表,然后释放它,以触发更新.
我想我可以将滑动手势识别器附加到桌子的基板视图上,但我想知道是否有办法直接从桌子本身拦截这个手势.
META:
我一直在浏览各种文档和诸如此类的东西.我之前没有这么做过,所以我从来没有想过.现在我看到我可能应该考虑一下.
如果这是一个明显的解决方案,我不介意被告知,只要你帮我找到"明显的"补救措施.如果这个问题不好,我会删除这个问题.
但是,我还没有找到解决方案,而且我通常都相当擅长这种事情.
更新我更改了标题以更好地反映我的要求.
我在UITableView单元格中显示来自服务器的数据有一个小问题.我有一个添加显示"提要"屏幕,类似于Instagram上的主屏幕.Feed的UITableView中的每个单元格都加载和映像以及来自服务器的一些文本(来自parse.com)
这是我的cellForRowAtIndexPath实现:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(HomeCell.reuseIdentifier(), forIndexPath: indexPath) as HomeCell
// Configure the cell...
let obj = tableArray[indexPath.section]
cell.configureWithObject(obj)
return cell
}
Run Code Online (Sandbox Code Playgroud)
tableArray是一个PFObjects数组
在HomeCell类中,configureWithObject方法使用SDWebImage加载此单元格的远程图像并设置所需的文本标签
func configureWithObject(object : PFObject) {
AppManager.sharedInstance().getTrackDetailsFromPost(object, block: { (error, obj) -> Void in
if error != nil
{
return
}
var artworkURL = ""
if let artworkString = obj?[Column.TracksArtwork.rawValue] as? String {
artworkURL = artworkString
}
self.albumArtwork.sd_setImageWithPreviousCachedImageWithURL(NSURL(string: artworkURL))
var trackTitle = ""
if let title = …Run Code Online (Sandbox Code Playgroud) 我正在使用AFNetworking从我的服务器下载文件.它工作正常.但我有一个问题:当我向上或向下滚动时,我的ProgressView更新了错误的单元格(UI,而不是数据).这是我的代码:
我的细胞:
AFHTTPRequestOperation *operation;
@property (weak, nonatomic) IBOutlet DACircularProgressView *daProgressView;
- (IBAction)pressDown:(id)sender {
AFAPIEngineer *apiEngineer = [[AFAPIEngineer alloc] initWithBaseURL:[NSURL URLWithString:AF_API_HOST]];
operation = [apiEngineer downloadFile:(CustomObject*)object withCompleteBlock:^(id result) {
} errorBlock:^(NSError *error) {
}];
__weak typeof(self) weakSelf = self;
apiEngineer.afProgressBlock = ^(double progress, double byteRead, double totalByToRead) {
[weakSelf.daProgressView setProgress:progress animated:YES];
};
}
- (void)setDataForCell:(id)object{
}
Run Code Online (Sandbox Code Playgroud)
我的桌子:
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:NSStringFromClass([CustomCell class])];
cell.backgroundColor = [UIColor clearColor];
CustomObject *aObject = [listObject objectAtIndex:indexPath.row];
[cell setDataForCell: aObject];
return …Run Code Online (Sandbox Code Playgroud) 我有一个UITableViewController约五个不同的静态细胞.在其中一个单元格中,我试图加载动态UITableView
在界面构建器中,我标记了主UITableViewController tableView0,然后我标记了动态tableView1.
每次我尝试加载控制器时都会崩溃.这是我到目前为止的粗略代码:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
switch tableView.tag {
case 0:
return 2;
case 1:
return 1;
default:
break;
}
return 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch tableView.tag {
case 0:
return 5;
case 1:
return 2;
default:
break;
}
return 0
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("ComboInfoCell", forIndexPath: indexPath) as! UITableViewCell …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个倒计时应用程序,它将显示年数......秒数,直到即将到来的日期.我希望能够在表格视图中查看多个倒计时.我有一些基本的逻辑,它们独立于tableview单元格来创建倒计时:
.
.
.
var timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "countdown", userInfo: nil, repeats: true)
func countdown() {
let hourMinuteComponents: NSCalendarUnit =
NSCalendarUnit.CalendarUnitYear |
NSCalendarUnit.CalendarUnitMonth |
NSCalendarUnit.CalendarUnitDay |
NSCalendarUnit.CalendarUnitHour |
NSCalendarUnit.CalendarUnitMinute |
NSCalendarUnit.CalendarUnitSecond
let timeDifference = userCalendar.components(
hourMinuteComponents,
fromDate: NSDate(),
toDate: date1.enteredDate as NSDate,
options: nil)
// Sample Output
println("Year: \(timeDifference.year)")
println("Month: \(timeDifference.month)")
println("Day: \(timeDifference.day)")
println("Hour: \(timeDifference.hour)")
println("Minute: \(timeDifference.minute)")
println("Second: \(timeDifference.second)")
}
Run Code Online (Sandbox Code Playgroud)
这很好用,控制台显示倒计时.但是,当我尝试从单元格中调用它时,我无法通过错误.
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [__ NSCFTimer row]:发送到实例的无法识别的选择器
这是不起作用的代码.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { …Run Code Online (Sandbox Code Playgroud) 我正在构建一个下钻的桌面视图,我遇到了一些问题.我正在使用prepareforsegue调用下一个视图,我正在使用didselectrowatIndexpath将数据从源视图传递到目标视图.
我有以下问题:1)当我选择一个单元格,则prepareforsegue被这意味着视图之前我的数据可以被传递到下一个视图2)我在didSelectRowAtIndexPath方法一performseguewithidentifier被称为didSelectRowAtIndexPath方法之前调用,它似乎两次调用segue(一次使用prepareforsegue初次调用,第二次调用performseguewithidentifier).
使用故事板将数据从一个tableview传递到另一个tableview的最佳实践是什么?调用下一个视图的最佳方法是什么?
以下是我的一些代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (level == 0) {
int muscleID = [muscleIDArray[indexPath.row] intValue];
NSLog(@"MuscleID: %i", muscleID);
NSArray *submuscleArray = [self submuscleGroup:muscleID valueForKeyPath:@"submuscleID"];
if (submuscleArray == nil || [submuscleArray count] == 0) {
currentMID = muscleID;
level = 2;
[self performSegueWithIdentifier:@"drillDown2" sender:self];
} else {
currentMID = muscleID;
level = 1;
[self performSegueWithIdentifier:@"drillDown" sender:self];
}
} else if (level == 1) {
level = 2;
currentSMID = [submuscleIDArray[indexPath.row] intValue];
[self performSegueWithIdentifier:@"drillDown2" sender:self];
} else …Run Code Online (Sandbox Code Playgroud) 我搜索了网站,我发现围绕这个主题的唯一线程仍然没有答案,所以我希望我会有更多的运气.
我相对肯定我想做的事情相当容易,但我似乎无法找到答案.
我有一个带有Uitext字段的视图控制器,当单击文本字段时,它会以模态方式显示搜索控制器.
以下是文本字段的代码,即SetAlertTableController.swift:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
if indexPath.section == 0 {
cell.textLabel!.text = "Set a Station Alert"
cell.backgroundView = UIImageView(image: UIImage(named: "red-full"))
cell.textLabel?.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.0)
cell.imageView!.image = UIImage(named: "metro-no-pad")
cell.textLabel?.textColor = UIColor.whiteColor()
var searchField = UITextField(frame: CGRectMake(60.0, 25.0, 250.0, 30.0))
searchField.backgroundColor = UIColor.whiteColor()
searchField.borderStyle = UITextBorderStyle.Line
searchField.borderStyle = .RoundedRect
searchField.placeholder = "Search Stations"
searchField.textColor = UIColor.lightGrayColor()
searchField.delegate = self
self.view.addSubview(searchField)
} else if indexPath.section …Run Code Online (Sandbox Code Playgroud) 我有UITableView哪些细胞包含一个UITextField.我UITableViewController是所有这些文本字段的代表.现在,当UITableViewController取消分配时,我想将所有文本字段的委托设置为nil.文本字段有一个标签,所以一旦我有一个单元格,我可以用它的标签来获取它.
问题是如何获得所有创建的细胞?要求UITableView对visibleCells回报率唯一可见的细胞,但它可能发生,有一排是不可见的,咬它仍然有我UIViewController作为代表.所以我真的需要以某种方式获得所有创建的细胞.cellForRowAtIndexPath做同样的事情,所以对我来说也不行.我在这里看到的唯一方法是将所有文本字段存储在数组中,但可能有更好的方法吗?
这是一些代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"reuseId"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"reuseId"];
UITextField *nameTextField = [[UITextField alloc] initWithFrame:nameTextFieldRect];
nameTextField.tag = TEXT_FIELD_TAG;
nameTextField.delegate = self;
[cell.contentView addSubview:nameTextField];
}
return cell;
}
-(void)dealloc
{
// todo: get all text fields and set theirs delegate to nil
}
Run Code Online (Sandbox Code Playgroud)
好吧,大多数答案都表明我不需要将委托设置为nil,但由于我是偏执狂,我怀疑以下情况是可能的:用户点击"返回"按钮,因此dealloc我view controller …
我收到以下错误:
'NSUnknownKeyException', reason: '[<FestiPay.MasterViewController 0x10070ae20> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cardSection.'
Run Code Online (Sandbox Code Playgroud)
它是TableView部分的出口.问题是,我已经删除了这个变量,并且该部分没有Connections Inspector.
如何删除参考?