无法删除 swift 中 NSURLConnection 中的 NSData 值
Unable to delete NSData values in NSURLConnection in swift
我正在 UITableView 中填充约会列表。单击 viewappointment 按钮后,约会值将通过 API 并使用 NSURLConnection 获取值。成功获得 5 个约会并填充到 UITableView 中。
如果我再次单击该按钮,将显示 10 个约会。
如果我再次单击,将显示 15 个约会。
重复相同的数据。我不知道如何停止重复。
我已经使用下面的行删除了在追加新数据之前已经存在的所有数据。请指导我。
appoApiData.setData(NSData()) //TO REMOVE ALL DATAS
编码部分:
//BUTON ACTION:
appointmentAPI() //FUNCTION CALL
func appointmentAPI()
{
let url = NSURL(string: baseURL + "appointment/getbyuser/" + String(sharedResources.shared.id))
let request = NSMutableURLRequest(URL: url!)
appoApiConnection = NSURLConnection(request: request, delegate: self)! //NSURLConnection Delegates Method Call
println("URL CONNEXN \(appoApiConnection)")
}
//NSURL CONNECTION DELEGATES
func connection(connection: NSURLConnection!, didReceiveResponse response: NSURLResponse!)
{
if(connection == appoApiConnection)
{
println("RESPONSE_APPO: \(response)")
}
}
func connection(connection: NSURLConnection!, didReceiveData conData: NSData!)
{
if(connection == appoApiConnection)
{
appoApiData.setData(NSData()) //CLEARING ALL PREVIOUS VALUES
self.appoApiData.appendData(conData)
println("appo_data \(appoApiData.length)")
//Button Click 1st time: appo_data = 5
//Button Click 1st time: appo_data = 10
//Button Click 1st time: appo_data = 15
// and so on....
}
}
在 didReceiveResponse
中将 NSMutableData
实例的长度设置为 0
func connection(connection: NSURLConnection!, didReceiveResponse response: NSURLResponse!)
{
if(connection == appoApiConnection)
{
appoApiData.length = 0
println("RESPONSE_APPO: \(response)")
}
}
并删除 appoApiData.setData(NSData())
我正在 UITableView 中填充约会列表。单击 viewappointment 按钮后,约会值将通过 API 并使用 NSURLConnection 获取值。成功获得 5 个约会并填充到 UITableView 中。
如果我再次单击该按钮,将显示 10 个约会。 如果我再次单击,将显示 15 个约会。
重复相同的数据。我不知道如何停止重复。
我已经使用下面的行删除了在追加新数据之前已经存在的所有数据。请指导我。
appoApiData.setData(NSData()) //TO REMOVE ALL DATAS
编码部分:
//BUTON ACTION:
appointmentAPI() //FUNCTION CALL
func appointmentAPI()
{
let url = NSURL(string: baseURL + "appointment/getbyuser/" + String(sharedResources.shared.id))
let request = NSMutableURLRequest(URL: url!)
appoApiConnection = NSURLConnection(request: request, delegate: self)! //NSURLConnection Delegates Method Call
println("URL CONNEXN \(appoApiConnection)")
}
//NSURL CONNECTION DELEGATES
func connection(connection: NSURLConnection!, didReceiveResponse response: NSURLResponse!)
{
if(connection == appoApiConnection)
{
println("RESPONSE_APPO: \(response)")
}
}
func connection(connection: NSURLConnection!, didReceiveData conData: NSData!)
{
if(connection == appoApiConnection)
{
appoApiData.setData(NSData()) //CLEARING ALL PREVIOUS VALUES
self.appoApiData.appendData(conData)
println("appo_data \(appoApiData.length)")
//Button Click 1st time: appo_data = 5
//Button Click 1st time: appo_data = 10
//Button Click 1st time: appo_data = 15
// and so on....
}
}
在 didReceiveResponse
中将 NSMutableData
实例的长度设置为 0
func connection(connection: NSURLConnection!, didReceiveResponse response: NSURLResponse!)
{
if(connection == appoApiConnection)
{
appoApiData.length = 0
println("RESPONSE_APPO: \(response)")
}
}
并删除 appoApiData.setData(NSData())